Skip to content

keep the git gutter peek's buttons near the marker that opened it - #19225

Merged
kevinushey merged 3 commits into
mainfrom
feature/git-gutter-peek-layout
Oct 23, 2026
Merged

kevinushey merged 3 commits into
mainfrom
feature/git-gutter-peek-layout

Conversation

@kevinushey

@kevinushey kevinushey commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #19204. On a wide editor the peek's Revert and Close buttons sat at the far edge of the editor, a long mouse trip from the gutter marker the user had just clicked.

  • Revert now follows the label with a 24px gap, so it stays near the marker that opened the peek.
  • Close is a small glyph at the end of the header, with the translated "Close" string as its tooltip and accessible label. It is the lesser action: clicking the marker again, Show Change, and now Escape all close the peek too. The glyph also returns focus to the editor, like the other peek actions.
  • Escape closes an open peek. The handler is an Ace keyboard handler registered only while the peek is open, inserted just above Ace's default bindings, so the completion popup and Vim or Emacs mode keep precedence over it.

No NEWS entry, since the gutter is unreleased.

Addresses #2846.

Verification

  • tests/panes/editor/git_diff_gutter.test.ts (server-dev): 40/40, with new steps for the close glyph and Escape.
  • Manual check against a dev server: label to Revert gap measures 24px; Escape and the glyph both close the peek and leave the editor focused.

Screenshot

The peek on an editor roughly 1600px wide: Revert sits beside the label, next to the marker that opened the peek; the close glyph is at the far edge.

Git gutter peek with Revert beside the label and a close glyph at the end of the header

On a wide editor the peek's Revert and Close buttons sat at the far edge
of the editor, a long mouse trip from the gutter marker the user had just
clicked. Revert now follows the label with a 24px gap; Close becomes a
small glyph at the end of the header, since the marker click, Show
Change, and now Escape all close the peek too; and the glyph focuses the
editor like the other peek actions. The Escape handler sits just above
Ace's default bindings, so the completion popup and Vim or Emacs mode
keep precedence.

Addresses #2846
@kevinushey kevinushey added this to the 2026.11 (Montauk Daisy) milestone Oct 22, 2026
@kevinushey
kevinushey requested a review from gtritchie October 22, 2026 18:00

@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.

Requesting changes for the Escape handling. As written, Escape to close the peek also interrupts a busy R session, and the handler can be dropped while a peek is open. Details inline, with a suggested approach on the addKeyboardHandler line.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
};

// Ace keyboard handler installed while a peek is open: a plain Escape
// closes it and is consumed, so it does not go on to interrupt R.

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 doesn't hold. Ace's stopEvent only stops propagation, and RStudio's own keydown listener is on the same textarea (AceEditorNative.java:238, wired up at AceEditorWidget.java:191), so it still runs. Its Escape branch (TextEditingTarget.java:703) doesn't check defaultPrevented, so with R busy (and default or Emacs keybindings) one Escape closes the peek and calls interruptR. Someone pressing Escape just to dismiss the peek will interrupt a running computation.

Having that branch return early when ne.defaultPrevented is set would let the peek (or anything else Ace handles) keep Escape for itself.

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, and fixed in dfbfc14 the way you suggested: DomUtils.isDefaultPrevented() plus an early return at the top of the Escape branch. One side effect: Escape in Ace multi-select mode now just exits multi-select instead of also interrupting R, which seems right. Emacs is unaffected; its Escape bindings are only in the occur and isearch sub-handlers.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
// Escape closes the peek while it is open. The handler goes in just
// above Ace's default bindings, so the completion popup and a Vim or
// Emacs mode, which own Escape while active, still see the key first.
this.editor.keyBinding.addKeyboardHandler(this.peekKeyboardHandler, 1);

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.

addKeyboardHandler(..., 1) doesn't survive RStudio rebuilding the editor's handlers. AceEditor.updateKeyboardHandlers() calls setKeyboardHandler, which removes every handler above the default one (ace-uncompressed.js:40916), while this.peek stays set. That happens when the file type is changed from the status bar's language menu, when Vim/Emacs keybindings are toggled (AceEditor.java:2945, :2969), and when the editor re-attaches (AceEditor.java:517). After any of those, Escape no longer closes the open peek.

Registering Escape once as an Ace command would avoid the add/remove bookkeeping: commands live in the default handler, which setKeyboardHandler never removes, and it's already the lowest-precedence handler, so the completion popup and Vim still see the key first.

editor.commands.addCommand({
   name: "closeGitPeek",
   bindKey: "Esc",
   isAvailable: function() { return !!self.peek; },
   exec: function() { self.closePeek(); }
});

(removed again in dispose).

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, I missed setKeyboardHandler popping everything above the default. Switched to an Ace command in dfbfc14, gated on isAvailable, with readOnly: true and removed in dispose. The e2e spec now round-trips editor_keybindings through Emacs with a peek open and checks Escape still closes it.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated

// Escape closes the peek while it is open. The handler goes in just
// above Ace's default bindings, so the completion popup and a Vim or
// Emacs mode, which own Escape while active, still see the key first.

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 completion popup and Vim do get the key first, but the Assistant's ghost text doesn't. Its Escape branch for revealed ghost text (TextEditingTargetAssistantHelper.java:2025) rejects the suggestion without stopping the event (unlike the next-edit branch at :1975), so the same keypress then reaches this handler and closes the peek too.

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 dfbfc14 by making the ghost-text branch stop the event when it resets the suggestion, as the next-edit branch does. One consequence to be aware of: Escape on revealed ghost text no longer also interrupts a busy R, matching the next-edit behavior.

closeButton.className = PEEK_CLASS + "-close";
closeButton.textContent = "\u00D7";
closeButton.title = this.strings.close;
closeButton.setAttribute("aria-label", this.strings.close);

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: line widgets are appended to the editor container after the textarea, so with Tab key always moves focus on, keyboard focus can land on Revert or this button. Escape pressed there never reaches Ace's textarea listener, so it doesn't close the peek; the user has to activate the × instead.

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.

Good catch. The peek element now handles Escape itself in dfbfc14, refocusing the editor and closing. Covered by a test step that focuses the close button first.

await executeCommand(page, 'vcsShowChange');
await expect(peek).toBeVisible({ timeout: 10000 });
await editor.focus();
await page.keyboard.press('Escape');

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 covers a freshly opened peek with R idle. Escape while R is busy (checking R wasn't interrupted) and Escape after the keyboard handlers are rebuilt (e.g. after a file-type change) aren't covered, and those are the two cases that currently break.

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.

Both added in dfbfc14. The R-busy step sleeps six seconds and asserts a marker that only prints if the sleep completes (assembled with paste0, since the console's echo of the command would otherwise match). The rebuild step toggles editor_keybindings to Emacs and back, polling the handler stack, then presses Escape.

// so does the close glyph at the end of the peek's header
await page.mouse.click(box.x + box.width - 3, box.y + box.height / 2);
await expect(peek).toBeVisible({ timeout: 10000 });
await peek.locator(PEEK_CLOSE).click();

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 description says the glyph returns focus to the editor, but this step only checks that the peek is gone. Asserting the editor has focus afterwards would cover the focusEditor() call.

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 dfbfc14.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

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

Passed Failed Skipped Flaky
2071 1 131 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 0 0 12 0
✅ desktop-macos 1022 0 46 2
❌ desktop-windows 1025 1 49 0
✅ setup 24 0 24 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 4d51c7a524357aaa27af1cfec012ea78d5d6f71d - Run #1653

…terrupting r

- Escape is registered once on the editor's command manager, with
  isAvailable gated on an open peek, instead of a keyboard handler added
  and removed around the peek: setKeyboardHandler drops every handler
  above the default one when RStudio rebuilds the stack (file type or
  keybinding changes, re-attach), which left an open peek without Escape.
- TextEditingTarget's Escape branch returns early when Ace already
  consumed the key, so closing the peek no longer also interrupts a busy
  R session.
- The Assistant's revealed-ghost-text Escape branch stops the event like
  the edit-suggestion branch does, so one press rejects the suggestion
  without also closing the peek.
- The peek handles Escape from its own buttons, where Tab can leave focus.
- e2e: Escape with R busy (sleep marker must still print), Escape after a
  keybinding round-trip rebuilds the handlers, Escape from the close
  button, and the glyph returning focus to the editor.
@kevinushey
kevinushey requested a review from gtritchie October 23, 2026 18:00

@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.

The new commit addresses everything from the last round. Three follow-ups, two of them in Screen reader support mode, where Ace adds its own Escape command; details inline.

// precedence, so the completion popup and a Vim or Emacs mode, which own
// Escape while active, still see the key first.
var self = this;
editor.commands.addCommand({

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.

With Screen reader support on, Ace's enableKeyboardAccessibility option adds its own always-available blurTextInput command on Esc to this same command manager (ace-uncompressed.js:50778). Both commands sit at the default position 0, and CommandManager.exec tries the last-registered one first (:47364), so whichever is added later wins.

For a file opened after ext-diff has loaded, the loader calls back synchronously (ExternalJavaScriptLoader.java:88), so initialize() registers closeGitPeek while building the gutter (TextEditingTarget.java:1677). registerPrefs then runs (:2164), and its enableScreenReader().bind fires immediately (TextEditingTargetPrefsHelper.java:248) and adds blurTextInput after it. Escape then moves focus out of the editor and the peek stays open. Turning the pref on with a file already open does the same. Documents restored at startup load ext-diff asynchronously, so they happen to come out in the right order.

Giving the command an explicit position makes it win regardless of order:

bindKey: { win: "Esc", mac: "Esc", position: 1 },

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: same-position commands are tried last-registered-first, so this depended on whether ext-diff or the screen reader pref got there first. Took the explicit position in 4d51c7a, and the e2e keyboard test now turns enable_screen_reader on with the file already open, opens a peek, and checks Escape closes it with focus still in the editor.

// its bindings claimed the key (closing the Git gutter peek,
// leaving multi-select), that press is spent and must not go
// on to interrupt R as well.
if (DomUtils.isDefaultPrevented(ne))

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 skips the interrupt for any Escape an Ace binding consumed, not just the peek's. With Screen reader support on and no peek open, Ace's blurTextInput consumes every Escape, so Escape in the source editor no longer interrupts R for those users. Before this change it moved focus out of the editor and also interrupted R. Leaving snippet tab stops or multi-select now also uses up the press, which is probably fine.

In the default mode with no popup open nothing consumes Escape, so the interrupt still works there. If the screen-reader case should keep interrupting, the guard would need to be narrower than defaultPrevented.

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.

Agreed on the reading. Keeping the guard as is: an Escape that an Ace binding consumed is spent, whether that binding was the peek, multi-select, snippet tab stops, or the screen reader blur. The old behavior for screen reader users was one press doing both (move focus out of the editor and interrupt R); the console's Escape and Session > Interrupt R still interrupt. Happy to narrow it if you think the editor-Escape interrupt matters for that mode.

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.

Keeping the guard as is is fine. The console and Session > Interrupt R still cover interrupting, so no need to narrow it.

await expect(peek).toBeVisible({ timeout: 10000 });
await page.keyboard.press('Escape');
await expect(peek).toHaveCount(0);
await expect(page.locator(CONSOLE_OUTPUT)).toContainText('slept-through', { timeout: 20000 });

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 checks that Escape doesn't interrupt R while a peek is open. There's no test anywhere in e2e/rstudio that Escape in the source editor still interrupts R without a peek, so a change that made every Escape defaultPrevented would remove Escape-to-interrupt with all tests passing. A companion step (Escape with R busy and no peek; the marker must not print) would guard the new check, and running the peek steps with enable_screen_reader on would cover the precedence issue above.

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.

Both added in 4d51c7a: a companion step with R busy and no peek, where Escape must drop the console's busy state within 10s and the marker must never print, and a screen reader step for the precedence case above.

@kevinushey
kevinushey requested a review from gtritchie October 23, 2026 18:42
@kevinushey
kevinushey merged commit 313c46c into main Oct 23, 2026
20 checks passed
@kevinushey
kevinushey deleted the feature/git-gutter-peek-layout branch October 23, 2026 19:14
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.

2 participants