mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Add API to open a file or diff editor on a specific selection range (fixes #30241)
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { join } from 'path';
|
||||
import { commands, workspace, window, Uri, ViewColumn } from 'vscode';
|
||||
import { commands, workspace, window, Uri, ViewColumn, Range, Position } from 'vscode';
|
||||
|
||||
suite('commands namespace tests', () => {
|
||||
|
||||
@@ -114,10 +114,15 @@ suite('commands namespace tests', () => {
|
||||
registration.dispose();
|
||||
});
|
||||
|
||||
let c = commands.executeCommand('vscode.diff').then(() => assert.ok(false), () => assert.ok(true));
|
||||
let d = commands.executeCommand('vscode.diff', 1, 2, 3).then(() => assert.ok(false), () => assert.ok(true));
|
||||
let c = commands.executeCommand('vscode.diff', Uri.parse('sc:a'), Uri.parse('sc:b'), 'Title', { selection: new Range(new Position(1, 1), new Position(1, 2)) }).then(value => {
|
||||
assert.ok(value === void 0);
|
||||
registration.dispose();
|
||||
});
|
||||
|
||||
return Promise.all([a, b, c, d]);
|
||||
let d = commands.executeCommand('vscode.diff').then(() => assert.ok(false), () => assert.ok(true));
|
||||
let e = commands.executeCommand('vscode.diff', 1, 2, 3).then(() => assert.ok(false), () => assert.ok(true));
|
||||
|
||||
return Promise.all([a, b, c, d, e]);
|
||||
});
|
||||
|
||||
test('api-command: vscode.open', function () {
|
||||
|
||||
@@ -260,6 +260,19 @@ suite('workspace-namespace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('openTextDocument, with selection', function () {
|
||||
return createRandomFile('foo\nbar\nbar').then(file => {
|
||||
return vscode.workspace.openTextDocument(file).then(doc => {
|
||||
return vscode.window.showTextDocument(doc, { selection: new vscode.Range(new vscode.Position(1, 1), new vscode.Position(1, 2)) }).then(editor => {
|
||||
assert.equal(editor.selection.start.line, 1);
|
||||
assert.equal(editor.selection.start.character, 1);
|
||||
assert.equal(editor.selection.end.line, 1);
|
||||
assert.equal(editor.selection.end.character, 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('registerTextDocumentContentProvider, simple', function () {
|
||||
|
||||
let registration = vscode.workspace.registerTextDocumentContentProvider('foo', {
|
||||
|
||||
Reference in New Issue
Block a user