Skip to content

Load diff editors only when needed - #19

Merged
itsmingjie merged 3 commits into
mainfrom
perf/lazy-edit-activation
Aug 31, 2026
Merged

itsmingjie merged 3 commits into
mainfrom
perf/lazy-edit-activation

Conversation

@itsmingjie

@itsmingjie itsmingjie commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

CodeView previously attached an editor to every text file as it entered the viewport. For partial diffs, attachment fetched the full file and highlighted it again. Scrolling through a large diff therefore caused visible lag and repeated "Loading editor…" messages. Live patch refreshes could repeat the same work.

The viewer now marks a file editable after the first click in its code. Scrolling no longer fetches full file contents or creates editors. The editor module also loads on demand.

The first click uses the browser's native caret hit test to preserve its line and character position. Line-number clicks still select lines for comments. Binary and deleted files remain read-only.

Checks

  • pnpm run lint
  • pnpm run format:check
  • pnpm test (86 tests)
  • pnpm run build:ui

Previously every non-binary file in the diff carried edit: true, so
CodeView attached a full editor to each file that scrolled into view.
Each partial patch-parsed diff then hydrated immediately through
loadDiffFiles: a full-contents fetch (flashing the 'Loading editor…'
indicator), an in-place metadata upgrade, and a whole-file re-highlight.
On large diffs this ran for every file while scrolling, and again after
every live patch refresh.

Files now enter edit mode on the first click into their code (the same
click-and-type flow as before). Scrolling no longer creates editors,
fetches file contents, or re-highlights full files, and the editor
module itself loads on first edit intent instead of at startup. The
caret is placed on the clicked line once the editor's document is
hydrated, and number-column clicks keep driving comment line selection.

Commit, discard, and diff-source switches end the open edit sessions.
The first click into a file focused the editor at the start of the
clicked line. Measure the character offset under the pointer from the
clicked line element (Range-based binary search over its text nodes, so
token spans, tabs, and wrapped lines measure correctly) and pass it to
Editor.focus once the document hydrates.
Use caretPositionFromPoint in Chrome and Firefox and caretRangeFromPoint
in Safari instead of measuring every character rectangle. These browser
APIs already account for token spans, tabs, wrapping, and shadow DOM.
Fall back to the start of the clicked line when no native caret is
available.
@itsmingjie itsmingjie changed the title Activate edit mode lazily per file Load diff editors only when needed Aug 31, 2026
@itsmingjie
itsmingjie merged commit 3998875 into main Aug 31, 2026
4 checks passed
@itsmingjie
itsmingjie deleted the perf/lazy-edit-activation branch August 31, 2026 16:35
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