Repository navigation
fix two visual-editor find gaps: multi-cursor commands and search-box seeding - #18651
Conversation
"Find and Add Next" (quickAddNext) and "Find All" (findAll) build a multi-cursor selection in an Ace editor, but both handlers called straight through to docDisplay_ -- the document's source editor. In visual mode that editor is hidden, so the commands did nothing visible no matter where the cursor was. Both now go through withActiveEditor, as the other Ace-requiring handlers in TextEditingTarget already do, so they act on the code chunk that has focus. They also join VisualMode's code-command list, so in prose -- where there is no Ace instance and ProseMirror has no multi-cursor concept -- they report as unavailable instead of silently doing nothing. Prose multi-cursor is not addressed: ProseMirror selections are a single range, and panmirror's find API exposes only single-selection operations. Addresses #16540.
Opening Find in source mode fills the search box with the selected text (TextEditingTargetFindReplace.showFindReplace). The visual editor's bar has no such behavior -- PanmirrorFindReplaceWidget.showFindReplace passes a null search term -- so the selection was ignored and the term had to be retyped. Reported in the comments on #16540. onFindReplace now seeds the visual editor's bar the same way, through the existing findFromSelection path, and applies source mode's rule for a usable term: non-empty and on a single line. VisualMode.getSelectedText() reads the focused code chunk's selection when there is one. The outer ProseMirror selection sees a chunk as a single node, so a selection made inside one was invisible to it -- which was also giving "Use Selection for Find" the wrong text in a chunk. Addresses #16540.
Keep the chunk-aware selection read out of getSelectedText(), whose paired writer replaceSelection() still addresses the outer ProseMirror editor: the rstudioapi get/set pair stays symmetric, and find reads through a getSearchSelection() of its own. Clear visual mode's active-editor reference when a focused chunk is destroyed. Detaching removes the editor's handlers without firing blur, so the reference would otherwise outlive the editor it names. Seed the visual editor's toolbar Find button from the selection as well, so it matches Ctrl+F and the source editor's own button. Scope the embedded-editor walk to the visible document, give the two new tests distinct chunk labels, hoist the shared focusChunk helper, and report cleanup failures rather than swallowing them.
offsetParent is null for a position: fixed element as well as a hidden one, so getClientRects() is the narrower test of the thing meant here.
getSearchSelection() reads panmirror_ when no chunk has focus, and panmirror_ is null while the editor is torn down for a format reload. getFindReplace() stubs itself out over that window; routing the toolbar button through showFindReplace() had put the read ahead of that guard. Scope the test locators: .ProseMirror:visible, matching the filter the page object applies for the same reason, and the find input to the visible bar within the source panel, since the console and every other open editor mount a FindReplaceBar sharing those automation classes.
…eter The seeding test now runs findFromSelection as well, on the other identifier in the chunk, so the assertion only passes if the find box moves off the term the previous step left there. AceEditor's visual-mode flag comes off the public constructor: visualModeChunk() is the only way to set it, so there is no positional boolean to get wrong. The class doc counts three targets to match.
A destroyed chunk is not coming back, so the destroy hook now hands the editor over through onActiveEditorDestroyed(), which clears the reference and disables the code commands together. A blur keeps its existing behavior: the commands deliberately outlive one, so that clicking a toolbar or the find box does not gray them out. Cover the source-mode branch of the two rerouted handlers, asserting on selection ranges so the document reaches the visual half of the test unedited, and pin the chunk selection before each command dispatch -- Ace's find() searches forward and reports nothing when it misses, which would otherwise fail later looking like a seeding regression. Promote visualModeChunk to a third bullet in the page object's list of targets, where the count already said three.
…seeding syncFromEditor tears the panmirror widget down for a format reload, but removeWidget() only detaches it: PanmirrorWidget overrides no onUnload, so the chunk editors' destroy hooks never run and activeEditor_ was left pointing into the discarded instance. Hand it over there as well. Revert the toolbar Find button seeding added earlier in this branch. Measured against the running IDE, it does nothing: with a word selected in prose, the button reopens the bar on its previous term, because the click moves focus off the editing surface before the handler reads the selection. Ctrl+F, which does not move focus, still seeds. The button keeps a comment saying why. The same measurement turned up a second gap, noted in the test rather than asserted: a prose selection made after a chunk has been focused does not seed either, though window.getSelection() reports it. Clearing activeEditor_ in onPanmirrorFocus does not change that, so the selection state is panmirror's and closing it is upstream work. Guard the source-mode half of the multi-cursor test with ensureSourceMode(): a .qmd can open straight into visual mode, where quickAddNext is now disabled and the test would fail on the command enable gate rather than an assertion.
Guard the format-reload call site on activeEditor_ != null, so it reads as "this editor died" rather than relying on onActiveEditorDestroyed's identity check being vacuous when handed its own field. Record at both call sites why neither clearing path is asserted: the reload needs a format comment that changes mid-session, and destroying a chunk moves focus to prose, where onPanmirrorFocus disables the code commands anyway, so that test would pass either way. Pin the chunk selection before each command in the multi-cursor test, as the seeding test already does -- Ace's find() searches forward from the cursor and is silent on a miss, which would otherwise read as a command regression.
The palette is the route that matters for these two commands: findAll has no shortcut and no menu entry, and quickAddNext's Cmd+D is disabled in the default keymap. It also takes focus out of the chunk on the way, so whether withActiveEditor survives it decides whether the fix reaches anyone. Driving Find All through the real palette puts three cursors in the chunk, so focus is restored before the command runs. Asserted on the cursor count rather than typed text, which reads the same wherever the palette leaves focus. Pin both guards in getSearchSelection(): a multi-line selection and an empty one each leave the find box as it was, and the bar still opens for the empty case, which is Ctrl+F with nothing selected.
…d-next-visual-mode
RStudio E2E - all platformsAll tests passed!
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 |
| - ([#2129](https://github.com/rstudio/rstudio/issues/2129)): Added horizontal and vertical split source editor views, with shared edits and independent navigation state. | ||
|
|
||
| ### Fixed | ||
| - ([#16540](https://github.com/rstudio/rstudio/issues/16540)): Fixed an issue where opening Find in the visual editor left the search box as it was, rather than filling it with the selected text the way source mode does. A selection made inside a code chunk now seeds the box too, and is what Use Selection for Find looks for there; both previously read the surrounding document selection, which sees a chunk as a single unit. |
There was a problem hiding this comment.
Bad merge: 33 release-note entries resurrected in their pre-#18644 long form, producing duplicates.
The merge of origin/main (b6ba0df) took both sides of the change made by 9b0f6ce "Shorten Autumn Hawkbit release notes (#18644)", which replaced 38 long entries with 36 short ones. The result: NEWS.md now opens with 73 entries instead of 36, and 33 issues appear twice -- once in the long form this branch re-added and once in the short form main has (e.g. #18356, #18602, #18631, #18507 twice-over, #17806, ...). Only the two #16540 entries belong to this PR.
git show FETCH_HEAD:NEWS.md | grep -o 'issues/[0-9]*' | head -80 | sort | uniq -d lists them. Re-resolve the merge so only the two #16540 lines are added on top of main's shortened list.
| // Not asserted in the e2e suite: destroying a chunk moves focus to | ||
| // prose, where onPanmirrorFocus disables the code commands anyway, so | ||
| // such a test would pass with or without this | ||
| target_.getVisualMode().onActiveEditorDestroyed(editor_); |
There was a problem hiding this comment.
onActiveEditorDestroyed() calls setCodeCommandsEnabled(false), which mutates global AppCommand state -- but chunk destruction is not scoped to the document the user is currently editing.
Scenario: doc A is a .qmd in visual mode with a chunk focused (activeEditor_ set). The user switches to tab B, a plain .R file -- TextEditingTarget.onDeactivate() runs visualMode_.unmanageCommands(), re-enabling the code commands for B. If A's chunk editor never received a blur while being hidden (activeEditor_ still points at it), closing tab A runs VisualMode.onClosing() -> panmirror_.destroy() -> every chunk's destroy hook -> onActiveEditorDestroyed(editor_) -> setCodeCommandsEnabled(false). Run Selected Line(s), Extract Function, Go To Definition, Reformat, and now Find All / Find and Add Next are all disabled while the user is editing B in source mode, and nothing re-enables them until they visit another markdown tab and leave it again (unmanageCommands() is the only caller that passes true).
Dropping the reference is the part that is actually needed here; consider having the destroy path only setActiveEditor(null) and leaving the enable/disable to the focus handlers, or gating the disable on the target still being the active document.
| void onQuickAddNext() | ||
| { | ||
| docDisplay_.quickAddNext(); | ||
| withActiveEditor((disp) -> |
There was a problem hiding this comment.
withActiveEditor() reads visualMode_.getActiveEditor(), and VisualModeChunk's blur handler sets it to null (setActiveEditor(null), VisualModeChunk.java:219) while setCodeCommandsEnabled() deliberately leaves the commands enabled across a blur. So in visual mode the command can still report enabled with no active editor, and this handler silently does nothing -- the same failure mode the PR is fixing.
Concrete repro: focus a chunk, select an occurrence, click into the find box (or any toolbar button), then press Cmd+D. quickAddNext() is enabled, activeEditor_ is null, nothing happens. Same for Find All.
Other chunk-targeting commands avoid this by going through visualMode_.performWithSelection(), which calls panmirror_.focus() first to re-establish the active editor. Worth considering that route here, or at least noting the residual gap.
The 960x540 window left a 453px-tall page in which the visual editor kept only ~55px of body once its find bar was open. Panmirror's footnote editor is a 160px panel pinned to the editor's bottom edge, so opening one pushed the body out of the editor entirely and Playwright found the find bar sitting over the footnote text. Xvfb on the server runners is 1920x1080, so there is no reason to be that tight. Addresses #16540. Claude-Session: https://claude.ai/code/session_01KX4jinQVfHBpZ6WvtJDGW3
The format-reload branch of syncFromEditor() nulls panmirror_ and rebuilds it asynchronously, but unlike onClosing() and the source activation path it left the idle DebouncedCommands running. A pending saveLocationOnIdle_ (nudged by the outgoing editor's last state change) then fired in that window and read panmirror_.getEditingLocation() off null; the CI stack decoded to exactly that timer. Suspend all three before tearing the editor down; the rebuilt editor creates and resumes fresh ones. Addresses #16540. Claude-Session: https://claude.ai/code/session_01KX4jinQVfHBpZ6WvtJDGW3
Once the selection is in a footnote, panmirror's 160px footnote panel stays pinned to the editor's bottom edge, and the buffered find keeps re-selecting the footnote match, so on the 1008x580 Windows desktop page nothing in the document body could be clicked afterwards. Move the footnote and console-sentinel steps to the end of the test. Addresses #16540. Claude-Session: https://claude.ai/code/session_01KX4jinQVfHBpZ6WvtJDGW3
With the footnote steps moved last, they now follow a Find seeded from the chunk; its 300ms buffered find fired just after the footnote click and re-selected the chunk match, closing the footnote editor before the note text was checked. Wait for it to land first, as the other seeding steps do. Addresses #16540. Claude-Session: https://claude.ai/code/session_01KX4jinQVfHBpZ6WvtJDGW3
Two visual-editor find gaps reported on #16540.
Find and Add Next / Find All did nothing in visual mode
"Find and Add Next" (
quickAddNext) and "Find All" (findAll) build amulti-cursor selection in an Ace editor. Both handlers in
TextEditingTargetcalled straight through to
docDisplay_, the document's source editor, so invisual mode they were aimed at an editor that isn't on screen: nothing visible
happened, wherever the cursor was.
Both now go through
withActiveEditor, the helper the other Ace-requiringhandlers in that file already use. Source mode is unchanged; in visual mode the
command acts on the code chunk that has focus. They also join the
setCodeCommandsEnabledlist inVisualMode, so in prose -- no Ace instance,and no multi-cursor concept in ProseMirror -- they report as unavailable rather
than silently doing nothing.
Not covered. The repro in the issue is in prose, and that half is not fixed
here. ProseMirror's
TextSelectionis a single range and panmirror's find API(
PanmirrorFindReplace) exposes only single-selection operations, somulti-cursor prose editing is an upstream feature request for quarto-dev/quarto
rather than something this repo can route around.
"Find and Select All" (
findSelectAll) is deliberately left alone. It isalready disabled in visual mode, and its only affordance is the "All" button in
the find bar; clicking that button blurs the chunk editor, which clears the
active editor, so the same routing would not help it.
Find did not pick up the selection in visual mode
Reported in the comments on the same issue. Opening Find in source mode fills
the search box with the selected text
(
TextEditingTargetFindReplace.showFindReplace); the visual editor's bar passesa null term instead, so the selection was ignored and the term had to be
retyped.
onFindReplacenow seeds it through the existingfindFromSelectionpath, under source mode's rule for a usable term (non-empty, single line).
VisualMode.getSelectedText()also now reads the focused chunk's selection. Theouter ProseMirror selection sees a chunk as a single node, so a selection made
inside one was invisible to it -- which had been giving "Use Selection for Find"
the wrong text in a chunk as well.
Testing
Two cases in
e2e/rstudio/tests/panes/editor/quarto_chunks.test.ts, both invisual mode:
selecting an occurrence and running Find and Add Next puts a cursor on the
next one so typing edits both, Find All takes every occurrence in that chunk,
and neither reaches the prose.
each land in the find box.
Each was confirmed to fail without the corresponding change, including
separately for each half of the first fix: without the
withActiveEditorrouting the multi-cursor edit never lands, and without the
VisualModeentriesthe commands stay enabled in prose.
AceEditor.visualModeChunk(page, marker)is new in the page object -- neitherexisting target can address a chunk's embedded editor (
activeEditor()returnsthe hidden source editor, and a plain marker walk matches that editor too, since
it still holds the whole document).
Addresses #16540.