Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2148: vertical split command #2158

Merged
merged 5 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class FileCommand extends node.CommandBase {

return;
} else if (this._arguments.name === '') {
if (this._arguments.position === FilePosition.NewWindow) {
await vscode.commands.executeCommand('workbench.action.splitEditor');
return;
}
const fileList = await vscode.window.showOpenDialog({});
if (fileList) {
const doc = await vscode.workspace.openTextDocument(fileList[0]);
Expand Down
38 changes: 38 additions & 0 deletions test/cmd_line/vsplit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ModeHandler } from '../../src/mode/modeHandler';
import {
setupWorkspace,
cleanUpWorkspace,
assertEqualLines,
assertEqual,
WaitForEditors,
} from './../testUtils';
import { runCmdLine } from '../../src/cmd_line/main';
import * as vscode from 'vscode';
import { join } from 'path';
import * as assert from 'assert';
import { getAndUpdateModeHandler } from '../../extension';

suite('Vertical split', () => {
let modeHandler: ModeHandler;

setup(async () => {
await setupWorkspace();
modeHandler = await getAndUpdateModeHandler();
});

teardown(cleanUpWorkspace);

test('Run :vs', async () => {
await runCmdLine('vs', modeHandler);
await WaitForEditors(2);

assertEqual(vscode.window.visibleTextEditors.length, 2, 'Editor did not split in 1 sec');
});

test('Run :vsp', async () => {
await runCmdLine('vsp', modeHandler);
await WaitForEditors(2);

assertEqual(vscode.window.visibleTextEditors.length, 2, 'Editor did not split in 1 sec');
});
});
26 changes: 26 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ async function createRandomFile(contents: string, fileExtension: string): Promis
}
}

/**
* Waits for the number of text editors in the current window to equal the
* given expected number of text editors.
*
* @param numExpectedEditors Expected number of editors in the window
*/
export async function WaitForEditors(numExpectedEditors: number): Promise<void> {
let waitForEditorChange = new Promise((c, e) => {
if (vscode.window.visibleTextEditors.length === numExpectedEditors) {
return c();
}

let editorChange = vscode.window.onDidChangeVisibleTextEditors(() => {
if (vscode.window.visibleTextEditors.length === numExpectedEditors) {
c();
}
});
});

try {
await waitForEditorChange;
} catch (error) {
assert.fail(null, null, error.toString(), '');
}
}

export function assertEqualLines(expectedLines: string[]) {
for (let i = 0; i < expectedLines.length; i++) {
let expected = expectedLines[i];
Expand Down