Skip to content

input: Clear the blink state when the cursor stops - #3139

Open
novakduc wants to merge 1 commit into
longbridge:mainfrom
novakduc:input-blink-cursor-stop-reset
Open

novakduc wants to merge 1 commit into
longbridge:mainfrom
novakduc:input-blink-cursor-stop-reset

Conversation

@novakduc

Copy link
Copy Markdown

Summary

BlinkCursor::stop, called from on_blur, resets the epoch but leaves paused
and visible holding whatever the last pause set. A blur inside the 300ms
pause window — tabbing away right after a keystroke — therefore leaves
paused == true on a stopped cursor. The next start then hits blink's
if self.paused early return, never moves the epoch off zero, and the
refocused input has a cursor that is not blinking.

// blink_cursor.rs
fn blink(&mut self, epoch: usize, cx: &mut Context<Self>) {
    if self.paused || epoch != self.epoch {   // <- a stale `paused` swallows `start`
        self.visible = true;
        return;
    }
    ...
}

The defect is in the tree today and is masked by accident: pause acts on any
cursor, blinking or not, so the next keystroke starts the loop again. That
accident is itself the bug in #3138 — it is what makes a programmatic
set_value blink an unfocused input forever. Fixing #3138 removes the mask, so
this wants to land first, or fixing one bug turns the other from hidden into
visible.

The fix

Clear paused and visible alongside the epoch, so a stopped cursor carries
nothing into the next focus. stop is the end of a blink loop; leaving two
flags behind from the middle of the previous one has no meaning for the next.

As a side effect the caret now appears the moment an input is focused, rather
than starting from whatever visible the previous focus happened to leave
behind.

Public API

No signature changes. One public function changes what it observes:
OtpState::cursor_visible now returns false after a blur, where the stale
flags could previously keep it true. Both call sites (gpui-component's
OtpInput and gpui-shell's otp_input) already gate the caret on focus, so
nothing changes on screen.

Verification

Automated

  • Added blurring_a_paused_cursor_leaves_the_next_focus_blinking: start, pause,
    stop, start — the caret must show immediately and hide one interval later.
    Confirmed red on current main, green with this change.
  • cargo test -p gpui-base --lib (989) and cargo clippy -p gpui-base --lib --tests -- --deny warnings pass at this commit; cargo fmt --check, typos
    and cargo machete are clean.

Manual

Not done. docs/ACCESSIBILITY-UI-TESTING.md is the required method for focus
and input behavior and it is macOS-only (./script/run-story-macos, the macOS
accessibility tree); this branch was written on Linux. The pass worth running on
the Input story: type a character, Tab away and Shift-Tab straight back within
300ms, and confirm the caret appears immediately and keeps blinking.

AI assistance

Written with Claude Code: the change and its test are AI-generated, reviewed and
run by me.

novakduc@arch

`BlinkCursor::stop`, called from `on_blur`, resets the epoch but leaves
`paused` and `visible` holding whatever the last `pause` set. A blur
inside the 300ms pause window — tabbing away right after a keystroke —
therefore leaves `paused == true` on a stopped cursor. The next `start`
then hits `blink`'s `if self.paused` early return and never moves the
epoch off zero, so the refocused input has a cursor that is not
blinking.

The defect is masked today, and masked by accident: `pause` acts on any
cursor, blinking or not, so the next keystroke starts the loop again.
That accident is itself a bug — it is what makes a programmatic
`set_value` blink an unfocused input forever — and the next commit
removes it. This one has to land first so that removing the mask does
not turn a hidden defect into a visible one.

Clear `paused` and `visible` alongside the epoch, so a stopped cursor
carries nothing into the next focus. As a side effect the caret now
appears the moment an input is focused, rather than starting from
whatever `visible` the previous focus left behind.

novakduc@arch
@novakduc

Copy link
Copy Markdown
Author

Prerequisite for #3140 (which fixes #3138). That PR removes the accident currently masking this defect, so this wants to land first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant