Repository navigation
Show a focus outline on Console output and fix Tab from it - #19818
Conversation
Target a stable class rather than the console's element id, so the progress dialog's output follows the same rules. Outline on :focus so Focus Console Output chosen with the mouse shows it, and keep the mouse mark when the window loses focus. Addresses #19812.
Its last caller was removed with the virtual console feature (#16105).
| }); | ||
| el.addEventListener("focusout", event -> | ||
| { | ||
| if (!DomGlobal.document.hasFocus()) |
There was a problem hiding this comment.
Bug: the rstudio-pointer-focus mark can stay set after focus has left the output. The next keyboard visit then shows no outline, which is the bug this PR fixes.
The mark is cleared only by a Tab keydown inside the output, by focusEnd(), or by a focusout that fires while document.hasFocus() is true. If focus leaves the output while the window is inactive, this early return skips it. If focus then comes back somewhere else, nothing clears the mark.
Example: click in the output to select text, switch to another app while a running script calls file.edit(), then come back with focus on the editor. Later, Tab onto the output from the Console toolbar: both the :not(.rstudio-pointer-focus) rule and the .rstudio-pointer-focus:focus-visible { outline: none } rule hide the outline.
Chromium does fire focusout when a focused chunk is removed (e.g. by trimExcess), so removal clears the mark there. Firefox may not fire it; I haven't checked.
Suggested fix: clear the mark whenever focus lands outside the output, e.g. with a document-level focusin listener that removes the class when its target isn't inside el (removed when the widget detaches). A return to the same chunk still keeps the mark.
There was a problem hiding this comment.
Fixed in 7948955. While the output is attached, a document-level focusin listener clears the mark whenever focus lands outside the output, including focus moved while the window was inactive. The focusout check stays, for focus moving into an iframe such as the Help pane, which fires no focusin in this document.
Checked on Server in Chromium: drag-select, switch tabs, move focus to the console input while away, then come back. The mark is cleared, and Tab onto the output shows the outline. Switching away and back without moving focus still keeps the mark, so Cmd+C shows no outline.
| void onFocusConsoleOutputEnd() | ||
| { | ||
| view_.getConsoleOutputWriter().focusEnd(); | ||
| if (!view_.getConsoleOutputWriter().focusEnd()) |
There was a problem hiding this comment.
Pre-existing: Focus Console Output still does nothing, and announces nothing, when the Console is hidden, e.g. with the Terminal tab selected in the Console pane, or another pane zoomed.
The Console pane is a ModuleTabLayoutPanel, which hides unselected tabs with display: none. So Element.as(last).focus() in focusEnd() doesn't move focus, yet focusEnd() returns true, and no announcement is made. onFocusLastConsoleError handles this by running activateConsole and retrying.
Possible fix: activate the Console and retry the same way, or return DomUtils.hasFocus(last) after focus() (as ToolbarKeyboardNavigation does) and announce a separate message. Fine as a follow-up if it's out of scope here.
There was a problem hiding this comment.
Leaving this as is: Focus Console Output stays a no-op while the Console is hidden.
| command chosen from a menu. A separate rule, so browsers without :has() | ||
| drop only this one and not the rule above. */ | ||
| .rstudio-console-output:not(.rstudio-pointer-focus):has(> [role="document"]:focus) { | ||
| outline: #8AA9DB solid 2px !important; |
There was a problem hiding this comment.
Pre-existing (contrast): this rule reuses the app-wide #8AA9DB outline. That's 2.39:1 against Textmate's Console background (#FFFFFF) and 2.22:1 against Solarized Light (#FDF6E3), below the 3:1 that WCAG 1.4.11 asks of a focus indicator.
The color is shared app-wide, but this is a new indicator, so it may be worth a darker outline for the Console region in light themes, or a color chosen by theme. Could also be a separate issue.
There was a problem hiding this comment.
Not changing it here. The outline color's contrast is a known issue that will be addressed product-wide.
| Assert.assertFalse(getCOW().focusEnd()); | ||
| } | ||
|
|
||
| public void testFocusEndAfterFormFeedClear() |
There was a problem hiding this comment.
Nit (tests): none of the new tests step back past an empty last chunk, which is the main change in focusEnd(). This test has a single chunk, so getPreviousSibling() returns null at once, and testFocusEndWithOutput never enters the loop.
Replacing the loop with a single check of the last child (return last != null && last.hasChildNodes()) would still pass all three tests.
Suggested test: write "hello\n", call ensureStartingOnNewLine(), then write a lone "\033" (VirtualConsole holds it back, leaving an empty last chunk), and assert focusEnd() returns true.
There was a problem hiding this comment.
Skipping this one; the extra coverage isn't worth it for this rarely used path.
| * The mark survives the window losing focus, since focus comes back to the | ||
| * same element without another mouse press. | ||
| */ | ||
| private void trackPointerFocus() |
There was a problem hiding this comment.
Nit (tests): no test covers the pointer-focus mark: set on mousedown, cleared on Tab, cleared on a focusout to outside the output, cleared by focusEnd().
These can be checked in a GWT test by dispatching events on getElement() and checking hasClassName. Without tests, losing one of these updates would bring back either the #6518 outline after Shift or Cmd+C, or a missing outline on keyboard focus.
There was a problem hiding this comment.
Skipping this one too, for the same reason.
| @@ -36,11 +42,39 @@ public ConsoleOutputWriter(VirtualConsoleFactory vcFactory, String a11yLabel) | |||
| { | |||
| vcFactory_ = vcFactory; | |||
| output_ = new PreWidget(); | |||
There was a problem hiding this comment.
Nit: after Ctrl+L or cat("\f"), the output <pre> is empty and 0px tall, but it still has tabindex="0" from PreWidget. Tab from the Console toolbar stops on it, announced as "Console Output", and in Chromium the outline collapses to a 2px horizontal line.
That's the same kind of empty stop this PR removes for pending input. You could drop the tabindex while the output is empty and restore it on the next output, or leave it if the line is good enough.
There was a problem hiding this comment.
Leaving this as is. The empty stop lasts only until the next command is echoed into the output, and in that state Focus Console Output announces "No Console output to focus".
| outline-offset: -1px !important; | ||
| } | ||
|
|
||
| /* Console output chunks are inline, so an outline on one traces each wrapped |
There was a problem hiding this comment.
Nit: this comment runs six lines. Could it be trimmed to the reason (chunks are inline, so the whole region is outlined; plain :focus also covers the command chosen from a menu), with the :has() fallback note moved to the commit message or shortened to one line?
| - ([#19746](https://github.com/rstudio/rstudio/issues/19746)): [Accessibility] Fixed an issue where the "Show Traceback" and "Rerun with Debug" text on a Console error didn't have enough contrast against the error's background in several light editor themes, including the default Textmate. With Textmate, contrast is now 5.4:1, up from 3.8:1. | ||
| - ([#19782](https://github.com/rstudio/rstudio/issues/19782)): [Accessibility] Fixed an issue where the Minimize, Maximize, Restore, and Close buttons on panes were too small to click easily. Each button is now a 24x24 pixel target, up from 14x14 on an open pane, 16x17 or 20x17 on the minimized Source and Console panes, and 16x24 or 20x24 on other minimized panes. | ||
| - ([#19786](https://github.com/rstudio/rstudio/issues/19786)): [Accessibility] Fixed an issue where some toolbar controls were too small or too close to their neighbors to click easily. | ||
| - ([#19812](https://github.com/rstudio/rstudio/issues/19812)): [Accessibility] Fixed an issue where the Console output had no visible focus indicator when reached with Focus Console Output (Ctrl+Alt+2, or Alt+Shift+2 on Windows and Linux) or the Tab key. An outline is now drawn around the whole output region. Pressing Tab from the output no longer stops on an empty element, or, with "Tab key always moves focus" off, moves focus out of the Console. Focus Console Output now announces when there is no output to focus. |
There was a problem hiding this comment.
Nit: the macOS shortcut is written "Ctrl+Alt+2" here, but the #19637 entry a few lines up writes the same kind of shortcut as "Ctrl+Option+7 on macOS, Alt+Shift+7 elsewhere". For consistency: "Ctrl+Option+2 on macOS, Alt+Shift+2 elsewhere".
There was a problem hiding this comment.
Changed in 1431591 to "Focus Console Output (Ctrl+`)", the preferred shortcut. Its binding in Commands.cmd.xml is Ctrl+`, which is Control on every platform, including macOS (the menu shows ⌃`), so the entry names that one shortcut.
A focusout while the window was inactive left the mark set, hiding the outline on the next keyboard visit. Addresses #19812.
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
…nsole (#19823) * Outline console output only after keyboard focus PR #19818 hid the output outline with a mouse mark that was cleared whenever focus left the output. A dialog or menu that handed focus back to a clicked chunk then showed the outline to a mouse user. Mark keyboard arrival in focusEnd() instead, and clear it on mousedown. Addresses #19812. * Check focus actually moves in the keyboard-mark persistence test Addresses #19812. * Show a minimized or hidden Console for Focus Console Output Focus Console Output called focus() on a chunk the browser wasn't rendering, so with the Console minimized, behind another tab, or hidden by a maximized pane, nothing happened and nothing was announced. It now activates the Console and waits for it to finish showing, sharing the retry loop Focus Last Console Error already used. Addresses #19812. * Test Focus Console Output restoring a hidden Console Run the hidden-Console restore cases for Focus Console Output as well as Focus Last Console Error, and add a case with the Console behind another tab. Addresses #19812.
Intent
Addresses #19812.
The Console output region showed no focus indicator when reached with Focus Console Output (Ctrl+` with alternates of Ctrl+Alt+2, or Alt+Shift+2 on Windows and Linux) or the Tab key. Keyboard movement around it also had problems, fixed here as well.
Approach
Focus indicator
consoleStyles.cssturned off the focus outline on the output<pre>and on its output chunks (from pressing Shift while highlighting text in console history causes spurious focus rectangles to show #6518, where pressing Shift with output selected drew a rectangle around each wrapped line). The chunks are inline, so an outline on one traces each wrapped line.focus-visible.cssoutlines the whole output region while a chunk has focus, using:has(). The rule lives there because GWT's CSS parser silently drops:has()in a CssResource. It's a separate rule, so a browser without:has()loses only this rule, not the app-wide outline.:focus(not:focus-visible) on the chunk, so Focus Console Output chosen from a menu with the mouse also shows the outline.ConsoleOutputWritermarks the output withrstudio-pointer-focuson mouse down, and clears the mark when focus lands outside the output (even while the window is inactive), on Tab, and in Focus Console Output. While it's set, no outline is drawn, so drag-selecting output and then pressing Shift or Cmd+C doesn't show one. The mark is kept when the window loses focus, since focus returns to the same element.rstudio-console-output, rather than the element id, so the git progress dialog's output follows them too.ShellWidgetnow usesaddStyleNamefor the obfuscated output style, becausesetStylePrimaryNamereplaced that class.Tab order
<pre>, which shows a typed-ahead command while R is busy, hadtabindex="0"and started out visible and empty. It was an extra, unlabeled tab stop between the output and the input, read as "Group" by VoiceOver. It is no longer a tab stop and starts hidden.Focus Console Output with no output
cat("\f"), which leaves an empty chunk), the command did nothing. It now leaves focus where it is and announces "No Console output to focus", like Focus Last Console Error does when there's no error.Also removes
focusConsoleWarningMessage, unused since the virtual console feature was removed (#16105); rstudio-pro has no callers either.Automated Tests
ConsoleOutputWriterTestscoversfocusEnd()with no output, with output cleared by a form feed, and with output. The focus indicator and Tab order are CSS and focus behavior, checked by hand (QA Notes).QA Notes
Checked on Server in Chromium:
cat("\f"), then Focus Console Output: focus stays in the input, and "No Console output to focus" is announced.Sys.sleep(3)) still shows the pending command.Shift+Tab from Focus Console Output's chunk lands on the output
<pre>itself, one extra stop with the outline unchanged. Moving between output chunks by keyboard is #19817.Documentation
None needed.
Checklist
NEWS.md