From c4224d86d911ad4edbe978e472a308edf4151a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E8=A1=A8=E5=93=A5?= Date: Wed, 3 Aug 2022 10:06:22 +0800 Subject: [PATCH] feat: improve editor focus behavior (#1448) * feat: improve editor focus behavior * fix: test case --- packages/editor/src/browser/tab.view.tsx | 2 +- packages/file-tree-next/__tests__/browser/file-tree.test.ts | 2 +- packages/file-tree-next/src/browser/file-tree.service.ts | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/browser/tab.view.tsx b/packages/editor/src/browser/tab.view.tsx index 9bbdd9f5ed..37e7079e82 100644 --- a/packages/editor/src/browser/tab.view.tsx +++ b/packages/editor/src/browser/tab.view.tsx @@ -318,7 +318,7 @@ export const Tabs = ({ group }: ITabsProps) => { }} onMouseDown={(e) => { if (e.nativeEvent.which === 1) { - group.open(resource.uri); + group.open(resource.uri, { focus: true }); } }} onDragOver={(e) => { diff --git a/packages/file-tree-next/__tests__/browser/file-tree.test.ts b/packages/file-tree-next/__tests__/browser/file-tree.test.ts index 939a112d1c..e1774832ba 100644 --- a/packages/file-tree-next/__tests__/browser/file-tree.test.ts +++ b/packages/file-tree-next/__tests__/browser/file-tree.test.ts @@ -313,7 +313,7 @@ describe('FileTree should be work while on single workspace model', () => { handleItemClick(fileNode, TreeNodeType.TreeNode); const fileDecoration = decorations.getDecorations(fileNode); expect(fileDecoration?.classlist).toEqual([styles.mod_selected, styles.mod_focused]); - expect(openFile).toBeCalledWith(fileNode.uri, { disableNavigate: true, preview: true }); + expect(openFile).toBeCalledWith(fileNode.uri, { disableNavigate: true, preview: true, focus: true }); }); it('Style decoration should be right while click with ctrl/cmd/shift', async () => { diff --git a/packages/file-tree-next/src/browser/file-tree.service.ts b/packages/file-tree-next/src/browser/file-tree.service.ts index 76344599c4..ba0786d5bd 100644 --- a/packages/file-tree-next/src/browser/file-tree.service.ts +++ b/packages/file-tree-next/src/browser/file-tree.service.ts @@ -772,7 +772,11 @@ export class FileTreeService extends Tree implements IFileTreeService { public openFile(uri: URI) { // 当打开模式为双击同时预览模式生效时,默认单击为预览文件 const preview = this.preferenceService.get('editor.previewMode'); - this.commandService.executeCommand(EDITOR_COMMANDS.OPEN_RESOURCE.id, uri, { disableNavigate: true, preview }); + this.commandService.executeCommand(EDITOR_COMMANDS.OPEN_RESOURCE.id, uri, { + disableNavigate: true, + preview, + focus: true, + }); } /**