diff --git a/docs/en/guide/editor.mdx b/docs/en/guide/editor.mdx index 6cd8d7a2b..ea9e23c1b 100644 --- a/docs/en/guide/editor.mdx +++ b/docs/en/guide/editor.mdx @@ -117,7 +117,7 @@ With tabs placed left or right, the tab column is as wide as its longest name, u | **Go to Next Splitter** | `⌥⇥` | `Alt+Tab` | | **Go to Previous Splitter** | `⌥⇧⇥` | `Alt+Shift+Tab` | -**Window › Editor Tabs** also offers **Split Down**, **Unsplit**, **Unsplit All**, **Move to Opposite Group**, **Open in Opposite Group** and **Change Splitter Orientation**. You can also drag a tab to an edge of the editor area to split it. +**Window › Editor Tabs** also offers **Split Down**, **Unsplit**, **Unsplit All**, **Move to Opposite Group**, **Open in Opposite Group** and **Change Splitter Orientation**. You can also drag a tab to an edge of the editor area to split it. In the Project view, **Open in Right Split** (`⇧↵` / `Shift+Enter`, also in the context menu) opens the selected file in the split to the right. ## View options diff --git a/docs/zh/guide/editor.mdx b/docs/zh/guide/editor.mdx index b9590096f..d5762f234 100644 --- a/docs/zh/guide/editor.mdx +++ b/docs/zh/guide/editor.mdx @@ -117,7 +117,7 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、 | **转到下一个拆分器** | `⌥⇥` | `Alt+Tab` | | **转到上一个拆分器** | `⌥⇧⇥` | `Alt+Shift+Tab` | -**窗口 › 编辑器标签页** 中还有 **向下拆分**、**取消拆分**、**全部取消拆分**、**移动到另一组**、**在相对组中打开** 和 **更改拆分方向**。也可以把标签页拖到编辑区的某一侧边缘来拆分。 +**窗口 › 编辑器标签页** 中还有 **向下拆分**、**取消拆分**、**全部取消拆分**、**移动到另一组**、**在相对组中打开** 和 **更改拆分方向**。也可以把标签页拖到编辑区的某一侧边缘来拆分。在 Project 视图中,**在右侧拆分中打开**(`⇧↵` / `Shift+Enter`,右键菜单中也有)会把选中的文件打开到右侧拆分中。 ## 显示选项 diff --git a/src/features/project-tree/ProjectView.test.tsx b/src/features/project-tree/ProjectView.test.tsx index 873cc1212..fad12b873 100644 --- a/src/features/project-tree/ProjectView.test.tsx +++ b/src/features/project-tree/ProjectView.test.tsx @@ -171,6 +171,27 @@ describe("ProjectView", () => { await waitFor(() => expect(rows()).toEqual(["acme/w/acme", "build", "src", "App.kt", "Util.kt", "README.md"])); }); + it("opens the selected file in the right split with ⇧Enter; a folder still expands", async () => { + dispatchViaKeymap(); + const { tree, row, rows } = setup(); + await waitFor(() => expect(rows()).toContain("README.md")); + fireEvent.mouseDown(row("README.md")); + tree.focus(); + fireEvent.keyDown(tree, { key: "Enter", code: "Enter", shiftKey: true }); + await waitFor(() => + expect(openFile).toHaveBeenLastCalledWith( + "/w/acme/README.md", + expect.objectContaining({ side: true, focus: true }), + ), + ); + openFile.mockClear(); + fireEvent.mouseDown(row("src")); + tree.focus(); + fireEvent.keyDown(tree, { key: "Enter", code: "Enter", shiftKey: true }); + await waitFor(() => expect(rows()).toContain("App.kt")); + expect(openFile).not.toHaveBeenCalled(); + }); + it("pastes the files Explorer copied into the selected folder, as copies", async () => { dispatchViaKeymap(); // What Explorer leaves on the clipboard: a path outside the project. diff --git a/src/features/project-tree/actions.ts b/src/features/project-tree/actions.ts index 191979b49..900f211de 100644 --- a/src/features/project-tree/actions.ts +++ b/src/features/project-tree/actions.ts @@ -24,9 +24,11 @@ import { openMoveDialog, openRenameDialog, openSelection, + openSelectionInRightSplit, paste, reloadFromDisk, revealInFinder, + selectedFiles, selectedNodes, type PathKind, } from "./operations"; @@ -291,6 +293,16 @@ export function registerProjectActions(): () => void { when: FOCUS, run: openSelection, }, + { + id: "project.openInRightSplit", + title: "Open in Right Split", + category: "Project View", + icon: "split", + when: FOCUS, + // Folders keep Enter's expand / collapse. + enabled: () => selectedFiles().length > 0, + run: () => openSelectionInRightSplit(), + }, { id: "project.rename", title: "Rename File…", diff --git a/src/features/project-tree/contextMenu.test.ts b/src/features/project-tree/contextMenu.test.ts index ff3891e28..143cbbbb0 100644 --- a/src/features/project-tree/contextMenu.test.ts +++ b/src/features/project-tree/contextMenu.test.ts @@ -142,6 +142,7 @@ describe("project view context menu", () => { "-", "Run 'a'", "-", + "Open in Right Split", "Open In", "-", "Local History", @@ -228,7 +229,7 @@ describe("project view context menu", () => { const l = labels(contextMenuItems([node(`${ROOT}/src`, true)])); expect(l).toContain("Mark Directory as"); expect(sub(contextMenuItems([node(`${ROOT}/src`, true)]), "Refactor")).toContain("Move Directory…"); - for (const fileOnly of ["Find Usages", "Reformat Code", "Optimize Imports", "Run 'a'"]) + for (const fileOnly of ["Find Usages", "Reformat Code", "Optimize Imports", "Run 'a'", "Open in Right Split"]) expect(l).not.toContain(fileOnly); }); diff --git a/src/features/project-tree/contextMenu.ts b/src/features/project-tree/contextMenu.ts index 239320ee0..82f6162ef 100644 --- a/src/features/project-tree/contextMenu.ts +++ b/src/features/project-tree/contextMenu.ts @@ -25,6 +25,7 @@ import { openFile, openMoveDialog, openRenameDialog, + openSelectionInRightSplit, paste, reloadFromDisk, revealInFinder, @@ -313,8 +314,9 @@ export function contextMenuItems(nodes: ProjectNode[]): MenuItem[] { // Contributed groups (Run / Debug '…', More Run/Debug ›), each followed by a separator. push(...menuGroupItems("projectView", menuGroupContext(nodes))); - // Open In › + // Open in Right Split / Open In › push( + files.length > 0 && openInRightSplitItem(files), submenu("openIn", "Open In", [ canRevealInFileManager() && { id: "finder", @@ -457,6 +459,16 @@ export function contextMenuItems(nodes: ProjectNode[]): MenuItem[] { return items; } +function openInRightSplitItem(files: ProjectNode[]): MenuItem { + return { + id: "openInRightSplit", + label: "Open in Right Split", + icon: "split", + shortcut: keyLabel("project.openInRightSplit"), + run: () => void openSelectionInRightSplit(files), + }; +} + /** Library sources (External Libraries) are read-only: copy, find and reveal only. */ function libraryMenuItems(nodes: ProjectNode[]): MenuItem[] { if (!nodes.length) return []; @@ -480,6 +492,7 @@ function libraryMenuItems(nodes: ProjectNode[]): MenuItem[] { { kind: "separator" }, !!folder && delegated("find.inPath", { directory: folder }, "Find in Files…", { icon: "search" }), !!folder && { kind: "separator" }, + nodes.every((n) => !n.dir) && openInRightSplitItem(nodes), submenu("openIn", "Open In", [ canRevealInFileManager() && { id: "finder", diff --git a/src/features/project-tree/operations.ts b/src/features/project-tree/operations.ts index c3240b4a4..18fb5d97d 100644 --- a/src/features/project-tree/operations.ts +++ b/src/features/project-tree/operations.ts @@ -127,14 +127,22 @@ function expandFolder(path: string) { // --------------------------------------------------------------------------- // Open -export async function openFile(path: string, opts: { preview?: boolean; focus?: boolean; external?: boolean } = {}) { +export async function openFile( + path: string, + opts: { preview?: boolean; focus?: boolean; external?: boolean; side?: boolean } = {}, +) { const editor = maybeEditorService(); if (!editor) { notifications().notify({ level: "warning", title: "No editor available", body: path, key: "project.noEditor" }); return; } try { - await editor.openFile(path, { preview: opts.preview, focus: opts.focus ?? true, external: opts.external }); + await editor.openFile(path, { + preview: opts.preview, + focus: opts.focus ?? true, + external: opts.external, + ...(opts.side && { side: true }), + }); } catch (e) { fail(`Cannot open ${nameOf(path)}`, e); } @@ -144,6 +152,16 @@ export function openSelection() { for (const n of selectedNodes()) if (!n.dir) void openFile(n.path); } +/** Files among the selected nodes, for actions that open them. */ +export function selectedFiles(): ProjectNode[] { + return selectedNodes().filter((n) => !n.dir && !n.placeholder && !n.member); +} + +/** Open in Right Split (⇧Enter): the selected files in the pane right of the current editor. */ +export async function openSelectionInRightSplit(nodes = selectedFiles()) { + for (const [i, n] of nodes.entries()) await openFile(n.path, { side: true, focus: i === nodes.length - 1 }); +} + // --------------------------------------------------------------------------- // New / rename diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts index 256f01d7a..d2ffc5adb 100644 --- a/src/platform/keymaps/intellij-macos.ts +++ b/src/platform/keymaps/intellij-macos.ts @@ -211,6 +211,7 @@ export const intellijMacos: Record = { "project.paste": ["Meta+V"], "project.copyAbsolutePath": ["Meta+Shift+C"], "project.open": ["F4", "Meta+Down"], + "project.openInRightSplit": ["Shift+Enter"], "project.findUsages": ["Alt+F7"], "project.reformatCode": ["Meta+Alt+L"], "project.optimizeImports": ["Ctrl+Alt+O"], diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.ts index 7bc7775bc..a6d715c65 100644 --- a/src/platform/keymaps/intellij-windows.ts +++ b/src/platform/keymaps/intellij-windows.ts @@ -212,6 +212,7 @@ export const intellijWindows: Record = { "project.paste": ["Ctrl+V", "Shift+Insert"], "project.copyAbsolutePath": ["Ctrl+Shift+C"], "project.open": ["F4"], + "project.openInRightSplit": ["Shift+Enter"], "project.findUsages": ["Alt+F7"], "project.reformatCode": ["Ctrl+Alt+L"], "project.optimizeImports": ["Ctrl+Alt+O"], diff --git a/src/platform/keymaps/vscode-macos.ts b/src/platform/keymaps/vscode-macos.ts index e8c711d5a..b15e5cc51 100644 --- a/src/platform/keymaps/vscode-macos.ts +++ b/src/platform/keymaps/vscode-macos.ts @@ -236,6 +236,8 @@ export const vscodeMacos: Record = { "project.paste": ["Meta+V"], "project.copyAbsolutePath": ["Meta+Alt+C"], "project.open": ["Meta+Down"], + // Explorer: Open to the Side. + "project.openInRightSplit": ["Meta+Enter"], "project.reloadFromDisk": [], "project.expandAll": [], "project.collapseAll": [], diff --git a/src/platform/keymaps/vscode-windows.ts b/src/platform/keymaps/vscode-windows.ts index 91a7d122c..5186c4ae0 100644 --- a/src/platform/keymaps/vscode-windows.ts +++ b/src/platform/keymaps/vscode-windows.ts @@ -45,6 +45,7 @@ export const vscodeWindows: Record = { "db.drop": ["Delete"], "project.copyAbsolutePath": ["Alt+Shift+C"], "project.open": [], + "project.openInRightSplit": ["Ctrl+Enter"], // Editing extras, image viewer (keyWhen: image focused) and Markdown editor layouts "code.cyclicExpandWord": [], "code.cyclicExpandWordBackward": [], diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 47714c2d3..000479e87 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1884,5 +1884,6 @@ "e.g. Reticulating splines…": "e.g. Reticulating splines…", "New playful word": "New playful word", "Restore Built-in Words": "Restore Built-in Words", - "None — type the Engine API URL below": "None — type the Engine API URL below" + "None — type the Engine API URL below": "None — type the Engine API URL below", + "Open in Right Split": "Open in Right Split" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 1700d3dc2..093c9b960 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -8285,5 +8285,6 @@ "e.g. Reticulating splines…": "例如:正在网格化样条曲线…", "New playful word": "新的趣味文字", "Restore Built-in Words": "恢复内置文字", - "None — type the Engine API URL below": "无(在下方输入 Engine API URL)" + "None — type the Engine API URL below": "无(在下方输入 Engine API URL)", + "Open in Right Split": "在右侧拆分中打开" }