Skip to content

show git changes side by side in the editor - #19212

Merged
kevinushey merged 38 commits into
mainfrom
feature/git-diff-split-view
Oct 23, 2026
Merged

kevinushey merged 38 commits into
mainfrom
feature/git-diff-split-view

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Fixes #19208. Stacked on #19204 (the Git gutter markers), which it builds on; the diff here is just the side-by-side part.

Tools > Version Control gains Show Changes Side by Side, a checkable command for files in a Git project. It opens a read-only pane on the left holding the version of the file last staged or committed, next to the live document on the right. Changed lines are highlighted on both sides (with the changed characters within them), padding keeps unchanged lines level across the two, scrolling and the mouse wheel move both sides together, and the counterpart of the cursor's line is outlined on the other side. The document stays editable, and the comparison follows as you type against the same base the gutter markers use, so the two always agree. An untracked file shows a notice in place of the base.

The view is a third kind of editor split (editorSplit = diff), so it is remembered across sessions like the others, Remove Editor Split closes it, Split Editor Right/Down replaces it (and vice versa), and Focus Other Editor Split moves between the document and the base. It hides along with the three gutter commands when the markers are turned off in Global Options > Git/SVN, and an open view closes when that happens.

Approach

  • Ace: a new acesupport module, rstudio/git_diff_split, subclasses SplitDiffView from Ace's ext/diff (already shipped by show git changes in the editor gutter #19204) and attaches it to the live editor and a base editor it creates with rstudio/loader, read-only and set up to match the live one (mode, wrap, tabs, renderer options, theme). The subclass overrides the parts of Ace's view that assume it owns both editors: it no longer forces editor options (custom scrollbar, active-line highlight, ...) on the live editor; its alignment padding is tracked and removed individually instead of wiping every line widget in both sessions on each realign, and a row already holding another widget (notebook chunk output, an equation preview) keeps it and goes without padding; detach no longer collapses the live selection; and the diff comes from the gutter rather than a recompute per keystroke.
  • Gutter: GitDiffGutter gains setSplitView, forwarding the base lines and each recomputed diff to the view. While a view is attached the peek stays closed (the view shows what it would, and the padding sits where it would go) and a marker click goes to the change instead. Whitespace-insensitive diffs are computed on stripped lines, so their character ranges are dropped before reaching the view.
  • GWT: TextEditingTargetGitDiffGutter owns the native view: it creates it once the gutter exists for the pane the widget provides (GitDiffSplitWidget, a layout slot that relays resizes), and resets the split to none when the gutter detaches. TextEditingTargetWidget.manageEditorSplit lays the pane out west of the editor; TextEditingTarget applies the diff split only when the gutter is available (a restored split for a document that can no longer show one falls back to a single view) and keeps the command's checked state in step with the active tab.
  • Styling: Ace's diff CSS keys its dark colors off .ace_dark, which RStudio's themes never set; themeStyles.css adds .editor_dark variants, plus the base pane and its notice.

Not in this PR: scrollbar change zones (need Ace's custom scrollbar), folding unchanged regions, and reverting a change from the base pane (Revert Change at Cursor and the gutter still do that).

Automated Tests

Added to e2e/rstudio/tests/panes/editor/git_diff_gutter.test.ts: the view opens with the index version read-only in the file's mode, highlights the changed lines on each side, keeps unchanged lines level (checked through documentToScreenRow on both editors), sends a marker click to the change rather than a peek, and follows an edit; Focus Other Editor Split moves between the two; a regular split and the view replace each other, the command toggles and reports its checked state, and the view closes and the command hides when the markers preference is turned off; a notebook chunk's output widget survives where the padding would have gone, through a realign; and an untracked file shows the notice. Passes locally in test:server-dev along with the existing gutter tests.

QA Notes

In a Git project, edit a committed file and run Tools > Version Control > Show Changes Side by Side; check the highlights in a light and a dark theme, that scrolling either side moves both, that typing on the right updates the comparison, and that Ctrl+1 (Cmd+1) moves between the two panes. Try Split Editor Right while the view is open, then the command again. Turn the markers off in Global Options > Git/SVN with the view open: it should close, and the command should leave the menu.

Documentation

None added; happy to add a line to the User Guide's Git page alongside the gutter markers if wanted.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

Marks lines added, changed, or removed relative to the Git index beside
the line numbers, updating as the user types. The diff is computed
client-side with Ace's ext/diff provider against the index version
fetched through a new git_diff_base_contents RPC. New pref
show_git_diff_gutter (Code > Display), on by default.

Addresses #2846
Next/Previous Change and Revert Change at Cursor commands (Tools >
Version Control), a peek widget opened by clicking a marker that shows
the index version with a Revert button, and the diff now honors the
ignore-whitespace preference.

Addresses #2846
…nds when off

Git integration can stay on for a project while the editor adornments
are turned off: the checkbox now lives with the other Git settings, and
Next/Previous Change and Revert Change at Cursor follow it.

Addresses #2846
… files

Review follow-ups: actions flush a pending diff before using it; marker
clicks also swallow click/dblclick so Ace's fold toggle stays out of it;
a base refresh closes the peek; the RPC applies the source loader's
line-ending normalization; empty files diff as pure additions/deletions
(the provider cannot take an empty side); ignore-whitespace matches git
diff -w; the gutter commands need a Git session.

Addresses #2846
…across unchanged refreshes

Gutter cells gain 6px of right padding while the gutter is attached so
the marker and its click target sit beyond Ace's fold arrow (which hangs
into the padding), and the peek now closes only when the base contents
actually change rather than on every re-fetch.

Addresses #2846
…d follow the focused editor view

The base RPC checks the index entry's mode (git ls-files --stage) so
symlinks and submodules are left unmarked, and no longer strips control
characters the editor keeps. A split editor view gets its own gutter fed
the same base, the cursor-driven commands act on the view that holds
the cursor, and visual mode disables them along with the other
source-editor commands.

Addresses #2846
… focus

The base RPC looks the path up with a literal pathspec and checks the
entry for exactly that path, so a symlink named like a glob cannot
borrow a regular file's entry; and the split editor view schedules the
same focus-triggered base refresh as the primary view.

Addresses #2846
…h-encoding, and strip ESC like the editor

The peek never displaces an existing line widget (Ace keeps one per row
and the notebook persists chunk output by enumerating them); the base is
keyed by encoding as well as path and re-fetched when a reopen with
another encoding completes; and the base drops ESC characters the way
the editor does when it loads a document.

Addresses #2846
The gutter re-syncs on the SourceFileSavedEvent a rename raises, so a
renamed document drops its old base at once; MathJax no longer adopts a
line widget of another kind on an equation's row, and a peek stacked
under another widget closes itself.

Addresses #2846
…t undone

Reverting from a peek (or the Revert Change command) used the base as last fetched; the focus-driven re-fetch arrives 500ms plus a round trip later, so staging the file in the Terminal while a peek was open and then clicking Revert restored the pre-staging text. The gutter now asks the Java side for a fresh base first (setBaseRefresher / refreshBase), and the peek's Revert goes ahead only if the peek survived that refresh, while the command reverts only the chunk that was under the cursor when it was issued.
…cannot be re-fetched

A revert deferred across the base re-fetch could land after the user had typed into the chunk's rows, where the chunk keeps its coordinates and the late revert would erase the edit; the gutter now counts document revisions and stands down when one happened meanwhile. A failed re-fetch no longer leaves the previous base in place for the revert to use: the base is dropped (markers and peek go) until the next refresh succeeds.
…r path

A revert waiting on the base re-fetch survived a Save As: the path change dropped the base but kept the callbacks, which then ran against the new path's base, whose chunks can share the old ones' coordinates. The callbacks now run as soon as the base is dropped, where they find nothing to revert.
Adds Tools > Version Control > Show Changes Side by Side: a read-only pane
with the index version of the file beside the live document, aligned and
highlighted from the gutter's diff, as a third kind of editor split.

Addresses #19208
@kevinushey kevinushey added this to the 2026.11 (Montauk Daisy) milestone Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

3 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
4196 3 298 1
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 14 0
❌ desktop-linux 1043 1 70 0
❌ desktop-macos 1049 1 65 0
❌ desktop-windows 1041 1 77 1
✅ server-linux 1025 0 44 0
✅ setup 36 0 28 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 6e1556331e35a4eb92fd2940f3b2334b544b92d6 - Run #1669

Base automatically changed from feature/git-gutter-diff to main October 22, 2026 02:41
@kevinushey
kevinushey requested a review from gtritchie October 23, 2026 17:40

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the side-by-side view against Ace's ext/diff sources. Inline comments below, roughly in order of impact. The main one is that character-level highlights only reach the view when no leading lines are shared with the base, which is rarely.

// Whitespace-insensitive diffs were computed on lines with their
// whitespace stripped, so their character ranges do not fit the text and
// only the line ranges are kept.
this.setChunks = function(chunks, ignoreWhitespace) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Character-level highlights only reach this method when the change starts on line 1. Ace's DiffProvider.compute returns charChanges, but offsetChunks in git_diff_gutter.js rebuilds each chunk as {old, new} whenever trimCommonLines finds a common prefix, so the charChanges are dropped.

Example: edit one word on line 40 of a committed file. prefix is 39, so no .inline marker is drawn. Edit line 1 instead and they appear.

In the tokenized fallback with prefix === 0, the charChanges that do get through hold column offsets into the token strings, not the real text.

The e2e selectors use :not(.inline), so no test exercises this. Fixing it would mean offsetChunks shifting charChanges rather than dropping them, and dropping them for the tokenized result.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4a7c985: offsetChunks now shifts the charChanges with their lines, and the tokenized fallback drops them (its columns describe tokens). The first side-by-side test now asserts an .inline marker for the d <- 40 change on line 5.

Comment thread src/gwt/acesupport/git_diff_split.js Outdated
if (session.getValue() !== text)
session.setValue(text);

this.emptyEl.style.display = lines ? "none" : "";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null base means more than "untracked" here:

  • the onError path in TextEditingTargetGitDiffGutter.refresh calls setBase(null, null)
  • a Save As or rename clears the base before re-fetching
  • attach() creates the view before the first fetch returns, e.g. when a session restores a document with editorSplit = diff

In each case the pane says the file has no staged or committed version. For a tracked file whose fetch failed, that stays up and is wrong. Could the notice be driven by the response's isTracked(), with nothing shown while loading or after an error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fd1b8e8: the notice is driven by the response's isTracked() (a new setUntracked on the view), so a failed fetch, a Save As, or the window before the first fetch returns leave the pane blank. Added a test that fails a re-fetch with the view open and checks the notice stays hidden.

this.emptyEl = emptyEl;

var loader = require("rstudio/loader");
var editor = loader.loadEditor(editorEl);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base editor only gets Ace's generic text-input label, "Cursor at row N". The primary and split editors get setTextInputAriaLabel(constants_.textEditor()). After Ctrl+1 moves focus here, nothing tells a screen reader user that this pane is the read-only staged/committed version.

Ace's textInputAriaLabel editor option prefixes the label, so a translated string passed in from GWT would cover it. The untracked notice is a plain div, so it isn't announced either.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fd1b8e8. The base editor gets textInputAriaLabel plus the attribute set directly (Ace only applies the option in its keyboard-accessibility mode, which is why RStudio sets the attribute on its own editors), and the notice is a role="status" live region. Both strings come from EditorsTextConstants.

Comment thread src/gwt/acesupport/git_diff_split.js Outdated
// Tokenization and folding come from a mode of the live session's kind.
// RStudio modes bind to the session they are built for, so the base
// session gets one of its own rather than sharing the live one.
this.syncSessionOptions = function(session, liveSession) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These session options, and RENDERER_OPTIONS above, are copied once at creation, and nothing listens for later changes. With the view open, toggling Soft Wrap, changing the file type, or turning on Show Whitespace only changes the live side. Alignment survives (SplitDiffView realigns on changeWrapMode and pads by screen rows), but the two panes stop looking alike.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mode, tab size, wrap mode/limit and font are now followed through their session/renderer events (4a7c985). The renderer options have no event, so fd1b8e8 re-checks them on the live renderer's afterRender, which any change to them triggers; the font/wrap test now also flips Show Whitespace and checks the base follows.

Comment thread src/gwt/acesupport/git_diff_split.js Outdated
var BASE_CLASS = "ace_git-diff-base";
var EMPTY_CLASS = "ace_git-diff-base-empty";

var EMPTY_MESSAGE = "This file has no staged or committed version to compare with.";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only user-visible string in the feature that isn't translated. The gutter's strings come from EditorsTextConstants via GitDiffGutterNative.create. Could this be passed in the same way?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fd1b8e8: gitDiffBaseEmpty (and gitDiffBaseEditor for the label) in EditorsTextConstants, en + fr, passed in through GitDiffSplitNative.create the same way as the gutter's strings.

// Options). Not on dismiss, where the split is torn down regardless.
if (diffSplitWidget_ != null && !dismissed_)
{
sentinel_.setProperty(TextEditingTarget.EDITOR_SPLIT,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disposeDiffSplit() above runs immediately, but this setProperty only reaches applyEditorSplit once the modifyDocumentProperties RPC succeeds. DocUpdateSentinel.applyProperties runs in onResponseReceived, and onError only logs. So the pane is blank for the round trip, and if the RPC fails it stays blank until the markers are turned back on.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and the same gap applied to a failed RPC. fd1b8e8 routes this through a closeDiffSplit command on TextEditingTarget that applies EDITOR_SPLIT_NONE to the view first and then persists it. Covered by a test that fails modify_document_properties while the markers are turned off and checks the pane is gone regardless.

SplitDiffView.prototype.searchHighlight.call(this, selection);
};

// Alignment padding is applied as line widgets without content. Ace's

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not verified in the app. Foreign widgets are kept here, but Ace's DiffHighlight.update still draws the aligned_diff stripes over the rows of every non-hidden entry in session.lineWidgets, not just this view's padding.

Chunk output and equation previews (both ChunkOutputWidget) set an opaque background, so they hide the stripes. The Assistant's ghost_text line widget has no background of its own, so a multi-line suggestion would be drawn over stripes while the view is open.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed against DiffHighlight.update; the ghost-text container has no background, so it would have shown. fd1b8e8 wraps both markers' update so that, for the duration of the draw, a foreign widget is replaced by a hidden copy of the same rowCount/rowsAbove (geometry unchanged, stripes skipped). The chunk-output test now asserts no aligned_diff markers on the live side.

public boolean focusOtherEditorSplit()
{
// the side-by-side diff has a read-only base editor to move between
if (diffSplitWidget_ != null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diffSplitWidget_ can exist with no native view: before the gutter attaches, or after detach() disposed the view while the close RPC is pending. GitDiffSplitWidget.focus() then does nothing, but this still returns true, so Ctrl+1 is swallowed. The comment just below asks for the opposite: report false when the split hasn't materialized.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5cb9dd0: GitDiffSplitWidget.focus() reports whether there was an editor to focus, and focusOtherEditorSplit returns that, so Ctrl+1 falls through until the gutter has attached.

}

this.diffSession.chunks = this.chunks = chunks;
this.align();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: every gutter update realigns from scratch, even when no chunk row changed, as when typing inside an already-modified line. Each realign removes and re-adds all padding, resets both row caches from row 0, and emits changeFold on both sessions, which forces full re-renders. Skipping align() when the chunks' row ranges match the previous call would avoid that on most keystrokes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one for a follow-up, filed as #19250. The padding is computed from screen rows, so with soft wrap a keystroke inside an already-modified line can change the padding without any chunk row changing, and a row-range comparison would skip a realign that is needed. Updates are also already coalesced (a microtask, or a typing pause when the diff is slow), which bounds the cost. A safe skip would compare the computed padding set against what is in place, which means taking over Ace's align(); the issue has the details.

character changes, striped alignment padding) for light themes and keys
its dark variants off .ace_dark, which RStudio's themes do not set; these
cover the dark editor themes. */
.editor_dark .ace_diff.insert {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.ace_diff-active-line (the counterpart-line outline) is listed in @external but has no .editor_dark override. Ace's dark border color (#75777a) is keyed off .ace_dark like the others, so dark themes keep the light #9191ac.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 480bc68 (.editor_dark .ace_diff-active-line { border-color: #75777a }).

…and cursor

The base pane now takes the live editor's font size and line height (its
own element sat under Ace's default font, so rows of differing pixel
heights drifted apart), opens scrolled to where the document is, and
mirrors later changes to the document's mode, tab size, and soft wrap,
wrapping at the document's effective column so unchanged lines stay level
however the splitter is placed.

Folds in the document are mirrored into the base when the view opens and
after each base refresh, and a refresh no longer unfolds the document:
replacing the base text removed its folds, and Ace's fold pairing carried
each removal over to the live counterpart.

Clicking into the base pane makes its document current (so commands route
to it) and schedules the base re-fetch, like a click into a split view.
The cursor-driven commands act on the change at the base cursor while
that pane holds focus, rather than the change under the document's
cursor, which moving around in the base leaves where it was.

The character ranges within a change survive the prefix trimming of the
diff (they were dropped when the first line was unchanged), and are
dropped from the tokenized fallback, whose columns describe tokens.
…addition from an empty base

Nested folds are mirrored into the base along with their parents, so that
expanding the outer fold from the base pane (which Ace's pairing turns into
a plain removal of the document's fold, nested folds and all) brings them
back in the document. The base takes a new mode whenever the document's
mode is of another kind, not only when it is of an unrelated kind (R's mode
derives from Text's, so a switch to Text was missed). And the base's row
for an addition to an empty file is its one empty row, not row -1.
Ace keys the dark color of .ace_diff-active-line off .ace_dark like the
other diff styles, which were already covered for RStudio's dark themes;
this one was listed in @external but had no .editor_dark override.
The diff pane exists before the gutter has put a base editor in it (and
after the editor has gone while the close is pending). focusOtherEditorSplit
reported true then while focusing nothing, so Ctrl+1 was swallowed; it now
reports false, as it does for a regular split that has not materialized.
…e, renderer options, own stripes, prompt close

Review follow-ups for the base pane:

- The "no staged or committed version" notice is driven by the fetch's
  isTracked() rather than by a null base, so a failed fetch, a Save As or
  the moment before the first fetch returns leave the pane blank instead
  of calling a tracked file untracked. The notice is a status live region.
- The base editor carries an aria-label (and Ace's textInputAriaLabel for
  its accessibility mode), and both strings come from EditorsTextConstants
  (en + fr) through GitDiffSplitNative, like the gutter's.
- The renderer options copied at creation (show invisibles, indent
  guides, fold widgets, ...) are re-checked as the live editor renders,
  so a preference changed with the view open reaches the base too.
- Ace's DiffHighlight stripes the rows of every line widget as alignment
  padding; a foreign widget (chunk output, a multi-line Assistant
  suggestion) is stood in for by a hidden copy during the draw.
- Turning the markers off closes the view at once through
  TextEditingTarget.closeDiffSplit, which applies the split state before
  persisting it, rather than leaving the pane empty for the property's
  round trip (or for good if it fails).

e2e: a test for the notice across a failed fetch; assertions for the
label, Show Whitespace following into the base, no stripes over chunk
output, and the view closing even when the property save fails.
…the view's own padding

Ace's fold sync pairs a fold made on one side with one on the other, but
a fold made over existing folds takes them in as nested folds by removing
and re-adding them, which took their counterparts away for good; the
counterpart now gets the nested folds too, so that expanding the fold from
either side (a plain removal of the counterpart, nested folds and all,
followed by the re-adding of this side's nested folds) brings them back on
both. And a fold whose counterpart would be empty used to fold away
whatever line widget sat on the next row of the other side, notebook chunk
output included; it now takes only this view's alignment padding.
… errors are not "untracked"

roborev findings (jobs 2860 and 2864):

- Soft wrap: the base copies the document's indentedSoftWrap (RStudio
  turns it off), or an indented line wraps onto more rows in the base.
- Ace reports a line widget added, removed or resized (chunk output run,
  collapsed, expanded) as a changeFold without an action, which its handler
  and ours ignored; the sides are now realigned on those, except for the
  events the view's own alignment raises (align() is marked while it runs).
- The padding widgets carry a mark (gitDiffPadding) instead of being kept
  in an array searched per widget per repaint, and the stripe override
  substitutes foreign widgets on the rows being drawn only.
- A removed fold's counterpart keeps the nested folds that have no twin on
  the removing side (folds of lines only that side has); they were lost
  when a parent was expanded from the other pane.
- The document's scroll offset is copied into the base only once there is
  a base; with none (untracked, or not fetched yet) Ace clamped it to the
  top and synced that back to the document.
- SessionGit: a blob that cannot be read (a failing required smudge filter)
  is an error rather than tracked=false, so the pane does not call a tracked
  file untracked.
- showLineNumbers is an editor option; asking the renderer for it logged
  "misspelled option" on every render.

e2e: tests for the lone nested fold, the untracked file's scroll offset and
the unreadable base; the long-file test wraps an indented line, and the
notebook test collapses and expands the output with the view open.
… realign in a frame of its own, index read failures are errors

roborev findings on aa0f3fb (job 2873):

- A removed fold's counterpart keeps its whole subtree: only the pair itself
  is undone, and a nested fold Ace re-adds on expansion brings back the very
  counterpart it was paired with (nested folds of its own included) rather
  than a new one. Nested folds with no twin on the removing side come back
  only if the removal turns out to be an expansion (Ace's expandFold empties
  the fold's nested list; removeFold does not), decided a microtask later.
  A fresh counterpart copies collapseChildren, for Fold All.
- A realign scheduled from within a render (a line widget's height being
  measured) could never run: Ace's render loop drops render requests chained
  from inside a render after a few in a row, so the realign waited for a
  render that nothing else asked for. scheduleRealign now also requests a
  frame from outside the loop. (This is what left the padding one row short
  after a chunk's output was expanded.)
- SessionGit: a failing ls-files is an error, as a failing cat-file already
  is, rather than tracked=false.

e2e: the nested-fold test now has a paired block with a live-only loop
inside it, expanded level by level from the base pane; the notebook test
waits for the output's row count to change before checking alignment, so
the collapse and the expansion are each exercised.
… notebook output without a change; no scroll sync without a base

roborev findings on a5a3807 (jobs 2880 and 2881):

- A fold's removal is reported the same way whether the fold is being
  expanded, taken into a fold being added around it, or removed outright;
  the sessions' expandFold and addFold are wrapped so that the counterpart
  is treated accordingly: kept (and nested by the new fold's counterpart)
  on nesting, removed with its lone nested folds and lazy Fold All levels
  restored on expansion, removed outright otherwise. The subFolds heuristic
  that stood in for this is gone.
- A fold whose lines are all added (or, from the base, all removed) folds
  nothing on the other side, and a mapped range has to run forward to be
  folded; a reversed one put a placeholder in an unchanged base line.
- align() pads the base for the document's own line widgets (chunk output)
  whether or not a change lies below them: Ace pads at change boundaries
  only, so a clean notebook with output sat misaligned from the output on.
  The change padding measures screen rows, so the widget is not counted
  twice.
- Scroll sync is off while there is no base (not fetched, none, or a failed
  re-fetch), since Ace clamps the empty base's offset and would drag the
  document to the top; the base rejoins the document when it is back.

e2e: the nested-fold test covers nesting from the base pane, Ctrl-click,
and Ace's lazy Fold All; new tests for a clean notebook's output and a
fold over added Python lines; the long-file test fails a refresh while
scrolled down.
…d for wrap-only differences, map folds against a current diff

roborev findings on c192278 (jobs 2885 and 2886):

- A fold added with collapseChildren (Fold All, a recursive collapse) drops
  the folds within instead of nesting them; its counterpart is added with
  collapseChildren on the range, so Ace does the same on the other side,
  and the dropped folds' counterparts go rather than being kept as nested.
- A widget on an added line is not padded for on its own: the padding at
  the end of the addition takes its rows in, and a row of padding at the
  mapped base row was counted on top of it.
- Two paddings on one row add up once each (the merge doubled rowsAbove).
- Padding that would land on another widget's row (chunk output) goes
  above the next line instead of being dropped, so the line after the
  output stays level with its counterpart.
- With a whitespace-insensitive diff and soft wrap, matched lines that
  wrap onto different numbers of rows are padded for.
- A fold added before the gutter has re-run the diff (undo restoring a
  removed, folded function) is mapped against a flushed diff.
- Folds are mirrored only once there is a base, and a mapped range has to
  fit the other side.
- The base editor follows enableKeyboardAccessibility.

e2e: the nested-fold test collapses recursively from the document; new
tests for output inside an inserted chunk, a first-row widget below a
leading insertion, a fold restored by undo, and a fold in an untracked
file; the notebook test pairs 'tail' with 'tail' and checks that no stripe
overlaps the output; the long-file test adds a wrap-only whitespace edit.
…s focused; fold lines, end-of-file output and displaced padding in the alignment

roborev findings on 7134df6 (jobs 2890 and 2891):

- An editing command (Comment/Uncomment, Reindent, ...) run with the
  cursor in the read-only base pane did its work on the document's own
  cursor, out of sight; withActiveEditor does nothing then, as it does
  when no editor is active in visual mode.
- Wrap-only differences: a fold line is compared as the one display line
  it is (its first row carries the wrap count, the folded rows show none),
  when both sides fold the same rows, with any padding below its last
  row; folded on one side only, the rows are passed over.
- Padding displaced by another widget keeps its two parts apart: below
  the line goes above the next line, above the line goes below the line
  before; neither onto another widget's row (above the first line there
  is nowhere else).
- A change boundary at the end of the document counts the last line's
  widget (chunk output on the last line of a file without a trailing
  newline), which Ace's measure clips away.
- No fold is mirrored without a base, folds made while the view is open
  included, and a mapped range has to survive Ace's clipping unchanged.

e2e: the focus test runs Comment/Uncomment from each pane; new tests for a
wrap-only difference under a fold and for output on an unterminated last
line; the untracked-file fold test folds while the view is open.
…es pair by their folds, Insert Chunk stays off the document from the base pane, font after a split switch

roborev findings on e6f5293 (jobs 2895 and 2896):

- A counterpart fold takes the other side's own fold range for the mapped
  first row when it spans the mapped rows: Ace maps the columns of a
  changed line only roughly (a space added inside the header, a longer
  name, put the mapped start past the end of the base's line), and the
  strict fit check left the base unfolded.
- Wrap-only differences pair fold lines by the folds they hold rather than
  by equal spans, so a fold with a change inside it (different spans on the
  two sides) is still compared as one display line.
- Insert Chunk and Insert Section, which edit the document directly rather
  than through withActiveEditor, do nothing while the base pane is focused.
- The base's font is checked again as the pane is laid out and aligned:
  built while the document's editor is out of the layout (switching from a
  regular split), it had no computed style to take.

Not changed: padding above the document's first line while another line
widget sits on that line (a leading deletion with a multi-line suggestion
on row 0). Ace shows one widget per row and owns its row count through
measurement, so there is nowhere to put that padding; $addWidget says so.

e2e: the wrap-fold test adds a statement inside the function; a test for a
fold on a line that differs in whitespace only; Insert Chunk from the base
pane in the notebook test; the split-switch test with a larger font.
…s, and only where the mode folds; code-running commands stay off the document from the base pane

roborev findings on a90daa8 (jobs 2899 and 2900):

- $counterpartRange asks the mode for its fold range only where the mode
  folds at all (plain text has no getFoldWidgetRange; a file switched to
  Text while folded threw), only for mapped rows within the document (a
  fold over an added first line maps to row -1), and takes it only over
  the very rows mapped: a structural fold that merely ends on the same row
  (a comment ending where a folded selection starts) is not the fold.
- The code-running commands (Run Selection/Line/Statement/Paragraph/
  Function/Section/Chunk, Send to Terminal, Profile, Run as Job) do nothing
  while the base pane holds the cursor, as the editing commands do, rather
  than running the document's own line or selection out of sight.

e2e: a plain-text file with a folded selection (mirrored over unchanged
lines; not from an added first line); the focus test runs the line from
each pane and counts the console's echoes.
@kevinushey
kevinushey requested a review from gtritchie October 23, 2026 21:42
…s its columns, commands go by the pane that held the cursor last

roborev findings on 58b1362 (jobs 2901 and 2902):

- The document's focus() goes back to the view the user was last in (the
  base pane, or a split view), as when a command run from the palette
  returns focus, so the command finds the cursor where it was.
- A folded selection takes the mode's own range on the other side only
  when it is the mode's fold itself (as against a selection, whose columns
  are its own); otherwise the mapped range is kept.
- The gutter's cursor-driven commands (Revert/Show Change at Cursor, Next/
  Previous Change) go by the pane that held the cursor last, not by focus
  at the time: a menu chosen with the mouse has taken focus to the menu.
- Run All Chunks Above/Below do nothing while the base pane holds the
  cursor, like the other code-running commands.
- The gutter flushes a pending diff before handing the view its first
  chunks (a slow diff's update waits out a typing pause).

e2e: the focus test switches tabs and back; the base-cursor test reverts
with focus in the console; the whitespace-only fold test folds a selection
over the same rows; the notebook test runs the chunk-range commands from
the base pane.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working through all of these. Every earlier comment is addressed, and deferring the realign work to #19250 makes sense given soft wrap. Two small notes inline, neither blocking.


if (fold.lineWidget) {
// alignment padding (no element) is laid out afresh anyway
if (fold.lineWidget.el)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think this branch can run. Ace's BaseDiffView.onChangeFold is replaced by the override below, and the override is the only remaining writer of fold.lineWidget. It only stores a widget that alignmentWidgets holds, and padding widgets are built without an el. So only the fold.lineWidget = null reset is needed, and dropping the hand-back would make it clearer that base folds never hold foreign widgets.

Comment thread src/gwt/acesupport/git_diff_split.js Outdated
marker.update = function(html, markerLayer, session, config) {
var widgets = session.lineWidgets;
if (widgets) {
session.lineWidgets = widgets.map(function(w) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this copies the whole lineWidgets array, one slot per row, on every back-marker draw of each editor, and Ace redraws back markers on every scroll frame. Rows without a widget return early, so it's cheap: running the same map in node took about 63 µs per draw at 10,000 rows and 350 µs at 50,000. DiffHighlight.update only reads config.firstRow to config.lastRow, so copying just that range would tie the cost to the viewport, if it's ever worth it.

…cus returning to the base pane shows the base cursor; the counterpart outline follows the diff

roborev findings on f32ceb7 (jobs 2909 and 2911):

- The editing and code-running guards go by the pane that held the cursor
  last among the document's views rather than by focus at the time: a
  command chosen from a menu with the mouse has taken focus to the menu.
- ensureCursorVisible() scrolls the base cursor into view when the base
  pane is the one focus went back to (Ctrl+1 from the console), rather
  than the document's cursor, which took both panes away from it.
- The outline of the cursor line's counterpart is redone after each diff;
  Ace redid it only on a selection change, so an edit above the cursor left
  the wrong base line outlined.

e2e: the notebook test runs the chunk-range commands with focus in the
console; the long-file test returns from the console with the cursors far
apart and checks the base cursor stays in view.
…alone

roborev finding on 812d471 (job 2915): onExecuteCodeWithoutMovingCursor
falls back to Select All Matches when the Find field, not an editor, has
focus; the base-pane guard ran ahead of that and swallowed the shortcut
whenever the base pane had held the cursor last. The guard now sits inside
the branch that runs code.

e2e: the focus test also runs the command from the base pane and counts no
new console echo.
…Alt+Enter; a widget aliased at a fold is padded for once

roborev findings on 812d471 and 7d1f038 (jobs 2916 and 2920):

- cursorInDiffBase() is false in visual mode, whose source views (base pane
  included) are hidden; the remembered pane otherwise kept Run and Insert
  Chunk from working in the visual editor.
- Alt+Enter with the base pane focused does nothing, rather than selecting
  the Find field's matches in the document and moving focus there.
- A line widget on the last row of a fold is listed at the fold's first
  row as well; it is padded for once, at its own row, so the panes keep the
  same height.

e2e: the long-file test waits out Ace's 500 ms scroll-sync guard before
each of its programmatic scrolls (the earlier run order could leave the
two panes apart).
…ane has focus; Ctrl+1 goes by the remembered pane; the focused view's cursor is shown

roborev findings on ba2afe4 (job 2922):

- The editor shortcuts that go to the last focused Ace editor (Ctrl+K, the
  assignment and pipe operators) edited the document while the base pane
  had focus; the base pane clears that editor as it takes focus, as visual
  mode does.
- Focus Other Editor Split goes by the pane that held focus last, so
  chosen from a menu with the mouse (focus in the menu) it still switches.
- ensureCursorVisible() shows the cursor of the view focus went back to (a
  split view included), not always the primary editor's.

e2e: the focus test runs the assignment-operator and yank shortcuts from
the base pane; the base-pane fold-widget click retries once when a gutter
re-render swallows it.
@kevinushey
kevinushey merged commit 297730d into main Oct 23, 2026
0 of 4 checks passed
@kevinushey
kevinushey deleted the feature/git-diff-split-view branch October 23, 2026 23:34
@kevinushey

Copy link
Copy Markdown
Collaborator Author

For the record: after the review fixes (480bc68, 5cb9dd0, fd1b8e8), the branch went through a roborev refine loop (aa0f3fb..ba2afe4 plus the final focus fixes) before the merge. The main themes:

  • alignment: padding for chunk output whether or not a change anchors it, inside insertions, at the end of the file, beside output (above the next line), and for wrap-only differences under Ignore Whitespace; realigning when a line widget is added, removed or resized, in a frame of its own (Ace's render loop drops renders chained past its recursion limit);
  • fold mirroring: expansion vs nesting vs outright removal told apart by wrapping the sessions' expandFold/addFold, lone nested folds and lazy Fold All levels restored, structural vs selection folds, mapped ranges validated after clipping, a fresh diff before mapping (undo), nothing mirrored without a base;
  • scroll sync off while there is no base; the base pane follows renderer options, font (also after a split switch) and indentedSoftWrap; git read failures are RPC errors rather than "untracked";
  • command routing while the base pane holds (or last held) the cursor: editing, code-running and chunk-range commands do nothing, Ace-level shortcuts (Ctrl+K, assignment/pipe) are not routed to the document, Ctrl+1 and Focus Other Editor Split go by the remembered pane and show that pane's cursor, Alt+Enter in Find is left alone.

Known leftovers: #19250 (skip the realign when padding is unchanged); below-line stripes under wrapped lines; padding above the document's first line while another widget sits there (Ace's one-widget-per-row model); e2e for Alt+Enter with a non-empty Find query and for screen-reader mode.

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.

Show git changes in a split (side-by-side) diff view in the editor

2 participants