From bc16117d21f72425de43b7e26596990645c08f1d Mon Sep 17 00:00:00 2001 From: Daniel Falbel Date: Mon, 5 Aug 2024 21:26:58 -0300 Subject: [PATCH] Bring focus to Data Explorer after second click (#4200) Added an event listener to `positronDataExplorerInstance` that listens to the `onRequestFocus` event and correctly regain focus via the editor service. --------- Co-authored-by: Jon Vanausdeln --- .../browser/positronDataExplorerInstance.ts | 8 +++++ .../browser/positronDataExplorerService.ts | 1 + .../dataexplorer/dataexplorer.test.ts | 29 +++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts b/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts index 6bb59a50ebf..8b7cd5834e1 100644 --- a/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts +++ b/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts @@ -20,6 +20,8 @@ import { TableSummaryDataGridInstance } from 'vs/workbench/services/positronData import { PositronDataExplorerLayout } from 'vs/workbench/services/positronDataExplorer/browser/interfaces/positronDataExplorerService'; import { IPositronDataExplorerInstance } from 'vs/workbench/services/positronDataExplorer/browser/interfaces/positronDataExplorerInstance'; import { ClipboardCell, ClipboardCellRange, ClipboardColumnIndexes, ClipboardColumnRange, ClipboardRowIndexes, ClipboardRowRange } from 'vs/workbench/browser/positronDataGrid/classes/dataGridInstance'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { PositronDataExplorerUri } from 'vs/workbench/services/positronDataExplorer/common/positronDataExplorerUri'; /** * Constants. @@ -109,6 +111,7 @@ export class PositronDataExplorerInstance extends Disposable implements IPositro private readonly _keybindingService: IKeybindingService, private readonly _layoutService: ILayoutService, private readonly _notificationService: INotificationService, + private readonly _editorService: IEditorService, private readonly _languageName: string, private readonly _dataExplorerClientInstance: DataExplorerClientInstance ) { @@ -142,6 +145,11 @@ export class PositronDataExplorerInstance extends Disposable implements IPositro this._tableDataDataGridInstance.selectColumn(columnIndex); this._tableDataDataGridInstance.scrollToColumn(columnIndex); })); + + this._register(this.onDidRequestFocus(() => { + const uri = PositronDataExplorerUri.generate(this._dataExplorerClientInstance.identifier); + this._editorService.openEditor({ resource: uri }); + })); } /** diff --git a/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerService.ts b/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerService.ts index 9f79e8e2312..a4be19ed686 100644 --- a/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerService.ts +++ b/src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerService.ts @@ -340,6 +340,7 @@ class PositronDataExplorerService extends Disposable implements IPositronDataExp this._keybindingService, this._layoutService, this._notificationService, + this._editorService, languageName, dataExplorerClientInstance ) diff --git a/test/smoke/src/areas/positron/dataexplorer/dataexplorer.test.ts b/test/smoke/src/areas/positron/dataexplorer/dataexplorer.test.ts index be6eaf5a65b..a62cc855ce5 100644 --- a/test/smoke/src/areas/positron/dataexplorer/dataexplorer.test.ts +++ b/test/smoke/src/areas/positron/dataexplorer/dataexplorer.test.ts @@ -169,12 +169,11 @@ df = pd.DataFrame(data)`; }); - after(async function () { - + afterEach(async function () { const app = this.app as Application; await app.workbench.positronDataExplorer.closeDataExplorer(); - await app.workbench.positronVariables.openVariables(); + await app.workbench.quickaccess.runCommand('workbench.panel.positronVariables.focus'); }); @@ -207,6 +206,30 @@ df = pd.DataFrame(data)`; expect(tableData.length).toBe(3); }); + + it('R - Open Data Explorer for the second time brings focus back [C701143]', async function () { + // Regression test for https://github.com/posit-dev/positron/issues/4197 + const app = this.app as Application; + + const script = `Data_Frame <- mtcars`; + await app.workbench.positronConsole.executeCode('R', script, '>'); + await app.workbench.quickaccess.runCommand('workbench.panel.positronVariables.focus'); + + await expect(async () => { + await app.workbench.positronVariables.doubleClickVariableRow('Data_Frame'); + await app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")').innerText(); + }).toPass(); + + // Now move focus out of the the data explorer pane + await app.workbench.editors.newUntitledFile(); + await app.workbench.quickaccess.runCommand('workbench.panel.positronVariables.focus'); + await app.workbench.positronVariables.doubleClickVariableRow('Data_Frame'); + + await expect(async () => { + await app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")').innerText(); + }).toPass(); + + }); }); }); }