Skip to content

Commit 638f5d8

Browse files
authored
fix: use currentOrPreviousFocusedEditor on search (#2761)
* fix: use currentOrPreviousFocusedEditor on search
1 parent f8a6597 commit 638f5d8

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/editor/src/browser/workbench-editor.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
336336
return this._currentEditorGroup as any;
337337
}
338338

339+
public get currentOrPreviousFocusedEditor(): IEditor | null {
340+
return this.currentEditorGroup && this.currentEditorGroup.currentOrPreviousFocusedEditor;
341+
}
342+
339343
async open(uri: URI, options?: IResourceOpenOptions) {
340344
await this.initialize();
341345
let group = this.currentEditorGroup;

packages/editor/src/common/editor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ export abstract class WorkbenchEditorService {
346346
*/
347347
currentEditor: IEditor | null;
348348

349+
/**
350+
* 和 currentEditor 不同,对于 DiffEditor 来说会取到上一次 focus 的 Editor
351+
*/
352+
currentOrPreviousFocusedEditor: IEditor | null;
353+
349354
/**
350355
* 当前焦点的编辑器资源
351356
*/

packages/search/src/browser/search.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ export class ContentSearchClientService extends Disposable implements IContentSe
579579
};
580580

581581
searchEditorSelection = () => {
582-
const currentEditor = this.workbenchEditorService.currentEditor;
582+
const currentEditor = this.workbenchEditorService.currentOrPreviousFocusedEditor;
583583
if (currentEditor) {
584584
const selections = currentEditor.getSelections();
585585
if (selections && selections.length > 0 && currentEditor.currentDocumentModel) {

0 commit comments

Comments
 (0)