Repository navigation
keep the git gutter peek's buttons near the marker that opened it - #19225
Conversation
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
gtritchie
left a comment
There was a problem hiding this comment.
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.
| }; | ||
|
|
||
| // 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
|
|
||
| // 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
…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.
gtritchie
left a comment
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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 },There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…o-interrupt and the screen reader case
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.
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.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.