feat(project-view): Open in Right Split (⇧Enter) (#3579)

The Project view opened a file in the current pane whatever the modifier and had no way to open one in a split. Open in Right Split opens the selected files in the pane to the right: ⇧Enter in the IntelliJ keymaps, ⌘Enter / Ctrl+Enter in the VS Code ones, and in the context menu before Open In (External Libraries too). On a folder ⇧Enter keeps expanding it.

Closes #3549
This commit is contained in:
l0ng-ai
2026-11-16 00:55:52 +08:00
committed by GitHub
parent a5c14a4c21
commit 76f0b3fc63
13 changed files with 80 additions and 8 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -117,7 +117,7 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、
| **转到下一个拆分器** | `⌥⇥` | `Alt+Tab` |
| **转到上一个拆分器** | `⌥⇧⇥` | `Alt+Shift+Tab` |
**窗口 › 编辑器标签页** 中还有 **向下拆分**、**取消拆分**、**全部取消拆分**、**移动到另一组**、**在相对组中打开** 和 **更改拆分方向**。也可以把标签页拖到编辑区的某一侧边缘来拆分。
**窗口 › 编辑器标签页** 中还有 **向下拆分**、**取消拆分**、**全部取消拆分**、**移动到另一组**、**在相对组中打开** 和 **更改拆分方向**。也可以把标签页拖到编辑区的某一侧边缘来拆分。在 Project 视图中,**在右侧拆分中打开**(`⇧↵` / `Shift+Enter`,右键菜单中也有)会把选中的文件打开到右侧拆分中。
## 显示选项
@@ -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.
+12
View File
@@ -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…",
@@ -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);
});
+14 -1
View File
@@ -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",
+20 -2
View File
@@ -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
+1
View File
@@ -211,6 +211,7 @@ export const intellijMacos: Record<string, string[]> = {
"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"],
+1
View File
@@ -212,6 +212,7 @@ export const intellijWindows: Record<string, string[]> = {
"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"],
+2
View File
@@ -236,6 +236,8 @@ export const vscodeMacos: Record<string, string[]> = {
"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": [],
+1
View File
@@ -45,6 +45,7 @@ export const vscodeWindows: Record<string, string[]> = {
"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": [],
+2 -1
View File
@@ -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"
}
+2 -1
View File
@@ -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": "在右侧拆分中打开"
}