diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts index 106ef702d6934..e2105f2e017fd 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts @@ -295,4 +295,19 @@ suite('vscode API - editors', () => { assert.strictEqual(document.getText(), Buffer.from(await workspace.fs.readFile(file)).toString()); } + + test('extEditor.selection can be empty #18075', async function () { + await withRandomFileEditor('foo', async editor => { + + assert.ok(editor.selections.length > 0); + + editor.selections = []; + + assert.strictEqual(editor.selections.length, 1); + assert.strictEqual(editor.selections[0].start.line, 0); + assert.strictEqual(editor.selections[0].start.character, 0); + assert.strictEqual(editor.selections[0].end.line, 0); + assert.strictEqual(editor.selections[0].end.character, 0); + }); + }); }); diff --git a/src/vs/workbench/api/common/extHostTextEditor.ts b/src/vs/workbench/api/common/extHostTextEditor.ts index 86a322348a8d2..b523bf14a8282 100644 --- a/src/vs/workbench/api/common/extHostTextEditor.ts +++ b/src/vs/workbench/api/common/extHostTextEditor.ts @@ -456,6 +456,9 @@ export class ExtHostTextEditor { if (!Array.isArray(value) || value.some(a => !(a instanceof Selection))) { throw illegalArgument('selections'); } + if (value.length === 0) { + value = [new Selection(0, 0, 0, 0)]; + } that._selections = value; that._trySetSelection(); },