[edit] Edit Focus Polish Improvements#1017
Conversation
Call `editor.focus()` with a one-based line number and optional zero-based character offset to replace the current selection with a collapsed caret at that position. Normalize out-of-range targets through the text document and preserve `preventScroll` behavior. Calls made before attachment remain no-ops.
Call `editor.focus()` with `lineNumber: "first-visible"` to place the caret on the first editable row whose top is inside the virtualized viewport. Use `offset` to keep the target below additional overlays. Expose viewport roots for virtualized files and diffs, account for sticky headers, and preserve focus when no eligible row exists.
Pass an `onAttach` callback through React CodeView `editOptions` for simultaneous file and diff sessions. Assert the provider receives the same callback while item-specific `onChange` routing remains isolated.
Enter edit mode from the playground or a virtualized surface: focus could miss the first visible line, and later row replacement could reclaim focus from another control. Fall back to the nearest scrollable viewport, defer onAttach until the live editable DOM is synchronized, and restore focus only while the editor already owns it. Document and demonstrate the opt-in autofocus recipe.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@codex review |
(why link to the section you are in, lol...)
This reverts commit f0772f0.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e44dfcb25
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A focused editor loses its caret when a full render replaces or moves the editable DOM, so typing stops until the user focuses it again. Capture focus intent before renderer mutations and restore it after the new DOM synchronizes. Cancel stale restoration when focus moves elsewhere, and coordinate deferred focus through the shared render queue.
Define component-owned view capture and restoration across files, diffs, and CodeView. Cover logical vertical positions, horizontal code scrolling, and recycle behavior before replacing the raw scroll-container API.
Allow editor surfaces to read and restore logical vertical positions without reaching into the virtualizer root. Support element and document roots with a browser-style scroll operation while preserving cached DOM reads.
Expose code scrollLeft through editable components and let virtualized variants return the Virtualizer or CodeView that owns vertical scrolling. Capture horizontal state before teardown clears the code elements.
Capture horizontal scrolling from the editable code surface and logical vertical scrolling from its Virtualizer or CodeView. Restore each axis through its owner so rebased CodeView positions remain correct and non-virtualized state omits unsupported vertical state.
Editor state should follow the editable code surface rather than a shared virtualized viewport. Capturing scrollTop ties per-file persistence to Virtualizer and CodeView and can move the viewer during state restoration. Persist only the code scroller's scrollLeft, remove the vertical owner bridge and obsolete scroll-container accessors, and leave vertical scroll APIs on their virtualizer owners.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 295d44e0b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const unifiedAST = this.hunksRenderer.renderCodeAST('unified', result); | ||
| const deletionsAST = this.hunksRenderer.renderCodeAST('deletions', result); | ||
| const additionsAST = this.hunksRenderer.renderCodeAST('additions', result); | ||
| this.editor?.__captureFocusForDOMReplacement(); |
There was a problem hiding this comment.
Guard the new internal editor hook
When an app supplies a custom/loosely typed DiffsEditor from createEditor or attachEditor instead of the built-in Editor, existing implementations won't have the new internal focus hook. This unconditional call runs during every FileDiff render, so those editors now throw before the diff can paint; make the hook optional at the type and call site (or provide a compatibility no-op) so existing custom editors keep working.
Useful? React with 👍 / 👎.
Mostly the was to improve some API paper cuts around line focusing with the editor
Editor.focus()with explicit line/character targeting and a'first-visible'mode that preserves scroll position.onAttachreliable across queued rerenders and virtualized recycling without targeting detached DOM or stealing focus from other controls.