Skip to content

fix: the command line keeps focus when the page writes a selection back into the Field (#98) - #105

Merged
Kyu-seok merged 2 commits into
mainfrom
issue-98
Nov 23, 2026
Merged

Kyu-seok merged 2 commits into
mainfrom
issue-98

Conversation

@Kyu-seok

Copy link
Copy Markdown
Owner

Summary

On Notion, a cursor move followed at once by : opened the command line, and a few milliseconds later Notion wrote the Cursor VimText had announced back to the DOM. A selection set inside a blurred editable root focuses it, so focus left the prompt and the keys typed next were the block's Normal keys.

The page's write and the person's click both arrive as a blur of the prompt's input. Chromium tells them apart on the event itself: FocusEvent.sourceCapabilities names the device behind a click's or Tab's focus change and is null for a script's.

 the command line's input blurs
+  blur names no device (a script's) and fewer than 3 retakes for this prompt
+    microtask                              # runs once the page's script is done, before any key
+      Field has focus → input.focus()      # the prompt keeps the keys
   a task later (Mirror.cancelOnBlur, #100)
     input is its tree's active element → nothing
     else → cancel as Esc does, focus left where it went

 Session.onFocus
   status.show()
+  command line open → return               # the root's focusin fires mid-write:
+                                           # after collapse, before extend
   read the Field, render
 Session.onCommandLineLeft                  # a click closed the prompt
+  Field has focus → read the Field, render # the click back into the Field, read now
   else → status.hide()

The Notion shape of the site-shapes fixture now writes its model's selection back after an untrusted selectionchange, as Notion does (18 ms; the tests widen it so the write lands after the prompt opens on a loaded machine).

docs/engine-seams.md gains "A page that writes its selection back".

Closes #98

Evidence

  • Before: npm run red-on-main -- -g '#98' tests/e2e/site-shapes.spec.ts tests/unit/session.test.ts → "every matching test is red on main": seven e2e tests and one unit test.

    w and : back to back, wait for the page's write, type noh, Enter
      expect the block's text unchanged   ✘ on main: o opened a line, h typed into it
      x deletes the character w moved to
    

    After: npm run check passes: 592 unit tests, 330 e2e, 0 flaky. npm run test:e2e:editors: 295 passed, 0 flaky (again on the pushed commit).

  • Seven Chromium pins in tests/unit/chromium-facts.test.ts, "A page that writes its selection back": the blur of a click (onto an input, onto text, into an editable root) and of Tab names a device; a script's focus() and a script's selection write name none, a script inside the task of the person's key included; the root's focusin fires between collapse and extend; a microtask from the blur runs after the script.

  • Covered on the Notion shape: w and b before :; / and ?; closed by Enter, by Esc and by an Enter that ends in a notice; Visual mode. A click back with the command line open, which the Session now reads at the close, is covered on a textarea, a Single-line Field, a contenteditable, inside a shadow root and on the Notion shape.

Merge Danger

Door: two-way

Blast Radius: command-line

  • Not checked on live Notion: that is Release 0.4.2 (store upload): the fixes since 0.4.1 #96's dogfooding pass. The fixture's write-back is modelled on one instrumented live run.
  • A page that writes its selection again every time it leaves the root would trade focus with the prompt; the prompt takes focus back three times at most, then is cancelled. Whether Notion does this is not known.
  • Any script that focuses the Field while the prompt is open (a page button calling its editor's focus()) now keeps the prompt open, on every Field kind. Esc still closes it.
  • sourceCapabilities is Chromium-only. Where it is missing every blur counts as the person's, which is A click away with the command line open is undone (the Field takes focus back), and the prompt's character stays in the Status Line #100's behaviour.
  • Two tests are green on main by design and carry no #98 tag: the retake cap's unit test, and the "typed with no pause" e2e, which passes there whenever the keys beat the page's write.
  • The code review ran on the version that told the person's blur by a timer; the switch to sourceCapabilities and the other fixes for its findings have not been reviewed again.

🤖 Generated with Claude Code

…ck into the Field (#98)

Notion takes the Cursor VimText announces into its model and writes it back
to the DOM some milliseconds later. After a move and `:` typed back to back
the command line's input has focus by then, and a selection set inside a
blurred editable root focuses the root: the prompt was cancelled (since
#100; before, left showing) and the keys typed next were Normal keys.

The page's write and the person's click both arrive as a blur of the input.
Chromium names the device behind a click's or Tab's focus change in
FocusEvent.sourceCapabilities and leaves it null for a script's. A blur
that names no device and leaves the Field focused now gives the input focus
back, in a microtask from the blur (Mirror.cancelOnBlur, byScript), three
times at most for one prompt. The Session no longer reads the Field on a
focus that arrives while the command line is open: the root's focusin fires
mid-write, where a Visual selection reads as a caret; a click back into the
Field is read when the prompt closes.

The Notion shape of the site-shapes fixture writes its model's selection
back as Notion does. Tests: seven Chromium pins ("A page that writes its
selection back"), seven e2e tests and one unit test named #98, all red on
main's source (npm run red-on-main -- -g '#98'); a click back with the
command line open on a Single-line Field and inside a shadow root.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…a write is in flight

A contenteditable write still pending when the command line opens (an edit
and `:` typed back to back) selects its range in the blurred host, a
script's blur like the page's. The prompt took focus back after each of the
write's three selections, and its commands then ran in the prompt's input:
`wx:` lost the deletion. The prompt now leaves focus alone while a write is
pending; the write lands and the prompt is cancelled, as before #98.

Tests: `x and : typed back to back` on a contenteditable (the deletion was
lost in five of five runs before this commit), and the page's write landing
while a search is being typed. docs/engine-seams.md says where the script
focus is pinned rather than "on every Field kind".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

Notion: the command line opened right after a cursor move loses focus back to the page

1 participant