Skip to content

Commit

Permalink
adding vertical split command
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosflorencio committed Jan 23, 2024
1 parent 9e419b7 commit cf216a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
15 changes: 14 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,19 @@ async function openFileUnderCursor(viewColumn) {
}

async function openFileUnderCursorInHorizontalSplit() {
await openFileUnderCursor(ViewColumn.Beside)
await openFileUnderCursor(ViewColumn.Beside);
}

async function openFileUnderCursorInVerticalSplit() {
await openFileUnderCursor(ViewColumn.Beside);
// saving the reference
// toggling the editor layout (vertical split) will make the editor lose focus
const lastActiveEditor = window.activeTextEditor;
await commands.executeCommand("workbench.action.toggleEditorGroupLayout");
if (lastActiveEditor) {
// focus the editor again
await window.showTextDocument(lastActiveEditor.document);
}
}

/**
Expand Down Expand Up @@ -511,6 +523,7 @@ function activate(context) {
commands.registerCommand("vsnetrw.open", openNewExplorer),
commands.registerCommand("vsnetrw.openAtCursor", openFileUnderCursor),
commands.registerCommand("vsnetrw.openAtCursorInHorizontalSplit", openFileUnderCursorInHorizontalSplit),
commands.registerCommand("vsnetrw.openAtCursorInVerticalSplit", openFileUnderCursorInVerticalSplit),
commands.registerCommand("vsnetrw.openParent", openParentDirectory),
commands.registerCommand("vsnetrw.openHome", openHomeDirectory),
commands.registerCommand("vsnetrw.rename", renameFileUnderCursor),
Expand Down
29 changes: 16 additions & 13 deletions tests/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,22 @@ describe("navigation", () => {
assert.doesNotMatch(text, /\.\.\//);
});

test("open the a file in a horizontal split", async () => {
const dir = await createTempWorkspace(["a.txt", "b.txt"]);
await execCommand("vscode.open", vscode.Uri.file(path.join(dir, "a.txt")));
assert.equal(vscode.window.tabGroups.all.length, 1)
await openExplorer();
await moveToLine("b.txt");
await execCommand("vsnetrw.openAtCursorInHorizontalSplit");
assert.equal(vscode.window.tabGroups.all.length, 2)
assert.equal(
vscode.window.activeTextEditor?.document.fileName,
path.join(dir, "b.txt"),
);
});
["vsnetrw.openAtCursorInHorizontalSplit", "vsnetrw.openAtCursorInVerticalSplit"].forEach((command) => {
test(`open the a file with ${command}`, async () => {
const dir = await createTempWorkspace(["a.txt", "b.txt"]);
await execCommand("vscode.open", vscode.Uri.file(path.join(dir, "a.txt")));
assert.equal(vscode.window.tabGroups.all.length, 1);
await openExplorer();
await moveToLine("b.txt");
await execCommand(command);
assert.equal(vscode.window.tabGroups.all.length, 2);
assert.equal(
vscode.window.activeTextEditor?.document.fileName,
path.join(dir, "b.txt"),
);
await execCommand("workbench.action.closeActiveEditor");
});
})
});

describe("refresh", () => {
Expand Down

0 comments on commit cf216a2

Please sign in to comment.