Repository navigation
test(e2e): expose active ace editor via automation bridge - #17775
Merged
Merged
Conversation
Adds window.rstudio.documents.activeEditor(), which returns the native Ace JS instance backing the active source document (or null). It maps through SourceColumnManager.getActiveNativeEditor -- the same path the GWT side already uses to track "the active doc" -- so callers no longer have to scan the DOM for a .ace_editor element. The DOM scan in getEditorContent and openExistingFile was the proximate cause of 8 consistent air_formatting test failures: the bare .ace_editor selector also matches ShellWidget's console scroll panel, dialog editors (IgnoreDialog, ViewFileDialog, EditSnippetsDialog, AceEditorPreview), and stale source editors left in the DOM after a tab close -- any of which could shadow the real editor and surface as an empty getValue() in reformatCode. Refactors: - getEditorContent() reads activeEditor()?.getValue() instead of iterating .ace_editor. - New openExistingFile() helper (utils/files.ts) waits on documents.active().path basename match + activeEditor() != null; writeAndOpenFile and SourcePaneActions.createAndOpenFile both delegate to it. - air_formatting.test.ts: openTestFile uses openExistingFile; focusEditor wraps its waitForFunction in a diagnostic catch so a future focus-drift failure reports the actual active element, the in-console / in-source-panel flags, and the source-pane ace count instead of an opaque predicate-timeout.
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
The basename-only readiness check could match the wrong active document when two open files share a basename (or, on case-sensitive filesystems, differ only in case). When the caller passes an absolute path, compare the full normalized path (case-insensitive, slashes normalized) instead. Relative / bare-basename inputs still fall back to basename match -- R resolves them against its own cwd, so the absolute form RStudio reports back is not known to the helper. Addresses roborev review #701 (MEDIUM).
3 tasks done
gtritchie
pushed a commit
that referenced
this pull request
May 27, 2026
getCompletionsInEditor was iterating document.querySelectorAll('.ace_editor')
and picking the first non-console match -- same bug ad175dc (#17775) fixed
for getEditorContent / openFile. On the failing tests the scan landed on a
stale empty source editor at DOM index 0 instead of the live editor at
index 1, so gotoLine + focus moved into the empty editor and Ctrl+Space
fired with nothing for the completer to anchor to.
Replace both the explicit-cursor and default-cursor branches with
window.rstudio.documents.activeEditor(), which maps through
SourceColumnManager.getActiveNativeEditor and reliably returns the
currently-active doc's editor. Also adds Session.getLength() to utils/ace.ts
so the default-cursor branch can stay typed.
Restores six autocomplete_extras.test.ts editor tests (pipe completions,
roxygen tags in .R/.Rmd/.qmd, already-used args pref, backtick-quoted
columns, _$ placeholder) and keeps the 14 autocomplete.test.ts tests
passing locally.
kevinushey
added a commit
that referenced
this pull request
May 27, 2026
empty-marker AceEditor was scanning .ace_editor DOM nodes and picking the first non-console match -- same stale-editor bug fixed in ad175dc (#17775) for openFile/getEditorContent and f84e454 (#17784) for autocomplete actions. on tests with a single open file the marker '' would trivially match, but the matched node could be a stale editor left in the DOM after a tab close rather than the live active editor. route empty marker through window.rstudio.documents.activeEditor() and keep the DOM-walk path for non-empty markers (still useful when a test needs a specific non-active tab).
4 tasks
kevinushey
added a commit
that referenced
this pull request
May 28, 2026
…tor (#17788) * test(e2e): pin desktop fixture window size to 1400x900 avoids dualwindowlayoutpanel auto-snapping the left column to maximize on the small (~1024x645) macos gh actions virtual display, which was hiding the source pane and breaking edit_suggestions tests. * test(e2e): route AceEditor('') through activeEditor bridge empty-marker AceEditor was scanning .ace_editor DOM nodes and picking the first non-console match -- same stale-editor bug fixed in ad175dc (#17775) for openFile/getEditorContent and f84e454 (#17784) for autocomplete actions. on tests with a single open file the marker '' would trivially match, but the matched node could be a stale editor left in the DOM after a tab close rather than the live active editor. route empty marker through window.rstudio.documents.activeEditor() and keep the DOM-walk path for non-empty markers (still useful when a test needs a specific non-active tab). * test(e2e): drop eval-based runOnEditor in AceEditor the previous shape stringified the user's callback via fn.toString() and reconstituted it in the browser with (0, eval)('(' + fnSource + ')'). that was the only way to ferry an arbitrary user function across the node->browser boundary through page.evaluate's single-arg form. replace it with page.evaluateHandle to resolve the editor once, then call handle.evaluate with the user's function natively (playwright serializes the function itself, no eval). overload run() so callers that pass no arg stay typed; callers that need multiple args wrap in an object. no behavior change for callers; the eval was a workaround the bridge has since obsoleted.
This was referenced Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
window.rstudio.documents.activeEditor()bridge method returning the native Ace JS instance for the active source document (ornull). Maps throughSourceColumnManager.getActiveNativeEditor-- same path GWT already uses to track the active doc.getEditorContent()and a newopenExistingFile()helper to use the bridge, eliminating the.ace_editorDOM scan that was the proximate cause of 8 consistentair_formattingfailures.air_formatting.test.tsfocusEditornow wrapswaitForFunctionin a diagnostic catch so a future focus-drift failure reports the actual active element rather than an opaque predicate timeout.Why the DOM scan was wrong
The bare
.ace_editorselector also matches:ShellWidget.java:279adds the class for styling)IgnoreDialog,ViewFileDialog,EditSnippetsDialog,AceEditorPreviewAny of those could shadow the real source editor and surface as an empty
getValue()inreformatCode, producing theExpected: not ""timeout the 8 failing tests were all hitting.Test plan
npm run test:desktop-dev -- -g "Air Formatting"-- 8/8 pass (was 0/8) in 47s, no flakesnpm run test:desktop-dev -- -g "Edit suggestions"-- thewriteAndOpenFilepath now goes throughopenExistingFiletoo, worth confirming