Skip to content

fix: a Field nested in an editable root takes focus back with its Cursor when the command line closes (#97) - #101

Merged
Kyu-seok merged 1 commit into
mainfrom
issue-97
Nov 22, 2026
Merged

Kyu-seok merged 1 commit into
mainfrom
issue-97

Conversation

@Kyu-seok

Copy link
Copy Markdown
Owner

Summary

On a Field nested in an editable root (a Notion block), the command line closing left the caret at the root's start, outside every block: the block had no focus by its own definition, the root's focus event resolved to the root, and the next key was typed into the page's header as text.

 the command line closes (Esc, Enter, or a notice replacing it)
   cm.focus() → Session.focusForEngine() → ContentEditableField.focus()
+    nested Field, root blurred:
+      select the Field's last selection inside it   # focuses the root; its focusin fires
+                                                    # during the call, the caret already in the block
+        Sessions.onFocusin → resolves to the block → Session.onFocus (marked: the Cursor stays)
+          render → setSelection                     # hasFocus() is true now, so it lands
     focusTarget().focus()
-      # caret at the root's start → resolves to the root → no Session → the key is the page's
+      # the root already has focus: nothing moves

A root that already has focus is left alone. The command line also closes a task after its input blurs, and a caret the person clicked into another block meanwhile stands.

Fields that are their own focus target (a textarea, a Single-line Field, a plain or shadow-root contenteditable host, the four rich editors) take the same path as before.

docs/engine-seams.md "Focus" and "Selection and focus" say what is true now; the Chromium fact the fix builds on is pinned in tests/unit/chromium-facts.test.ts, "Selection and focus".

Closes #97

Evidence

  • Before: npm run red-on-main -- tests/e2e/site-shapes.spec.ts → "every file is red on main": the eight closing tests fail there.
    After: npm run check passes: 579 unit tests, 271 e2e, 0 flaky. npm run test:e2e:editors: 295 passed, 0 flaky.
Notion shape (#notion, caret Activated in block #n-two); each asserts the root focused,
the caret in #n-two, and the root's whole text:
  w, then ":" Esc | "/" Esc | "?" Esc | :noh Enter | :bogus Enter (a notice), x
      → "line ne": the character w moved to is deleted; .controls, title and #n-one unchanged
  w v e : Esc x               → "line ": the Visual selection held is deleted
  w i|R Ctrl-o :bogus Enter Z → "line Zone": Z is inserted at the Cursor
guard (green on main, red without the blurred-root check):
  w : click into #n-one       → the caret stays in #n-one, the text unchanged
unchanged: "3x, ., u, Ctrl-r and :q" on the Notion shape stays green

Merge Danger

Door: two-way

One method, ContentEditableField.focus(); reverting the commit restores the old behaviour.

Blast Radius: nested-Fields

Sessions.reconcile also calls focus(): a nested Field the page blurred in answer to a remembered Activation key now gets its caret back and keeps its Session, where before it was disposed. That path is untested.

🤖 Generated with Claude Code

…sor when the command line closes (#97)

The engine's re-focus focused the root alone, which left the caret at the
root's start, outside every block: the block had no focus by its own
definition, the root's focus event resolved to the root, and the next key
was typed into the page as text.

ContentEditableField.focus on a nested Field now puts its last selection
back inside it while the root is blurred. That focuses the root, and the
root's focusin fires during the call with the caret already in the Field,
so the event resolves to the Field and its Session's focus handler runs
inside Session.focusForEngine's mark. A root that already has focus is
left alone: the command line also closes when its input blurs, and a
caret the person clicked into another block meanwhile stands.

Fields that are their own focus target take the same path as before.

Coverage (CODING_STANDARDS rule 5), on the fixture's Notion shape: Normal
mode for Esc in : / ? and Enter on :noh and on an unknown ex command,
Visual mode, Insert and Replace through Ctrl-o, and a click into another
block with the command line open. A nested Field inside an open shadow
root is not covered. The eight closing tests are red on main; the
click-away test is green there and red without the blurred-root guard.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Kyu-seok
Kyu-seok merged commit 7718e41 into main Nov 22, 2026
1 check passed
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.

On a page of nested editable blocks (Notion), closing the command line leaves the caret outside the block and Normal keys are typed into the page

1 participant