Merge pull request #234858 from rgrunber/fix-63129

Expose adjustWhitespace to TextEditor API.
This commit is contained in:
Matt Bierner
2025-01-31 10:21:13 -08:00
committed by GitHub
13 changed files with 87 additions and 12 deletions

View File

@@ -94,6 +94,37 @@ suite('vscode API - editors', () => {
});
});
/**
* Given :
* This is line 1
* |
*
* Expect :
* This is line 1
* This is line 2
* This is line 3
*
* The 3rd line should not be auto-indented, as the edit already
* contains the necessary adjustment.
*/
test('insert snippet with replacement, avoid adjusting indentation', () => {
const snippetString = new SnippetString()
.appendText('This is line 2\n This is line 3');
return withRandomFileEditor('This is line 1\n ', (editor, doc) => {
editor.selection = new Selection(
new Position(1, 3),
new Position(1, 3)
);
return editor.insertSnippet(snippetString, undefined, { undoStopAfter: false, undoStopBefore: false, keepWhitespace: true }).then(inserted => {
assert.ok(inserted);
assert.strictEqual(doc.getText(), 'This is line 1\n This is line 2\n This is line 3');
assert.ok(doc.isDirty);
});
});
});
test('insert snippet with replacement, selection as argument', () => {
const snippetString = new SnippetString()
.appendText('has been');

View File

@@ -1227,6 +1227,27 @@ suite('vscode API - workspace', () => {
assert.deepStrictEqual(edt.selections, [new vscode.Selection(0, 0, 0, 3)]);
});
test('SnippetString in WorkspaceEdit with keepWhitespace', async function (): Promise<any> {
const file = await createRandomFile('This is line 1\n ');
const document = await vscode.workspace.openTextDocument(file);
const edt = await vscode.window.showTextDocument(document);
assert.ok(edt === vscode.window.activeTextEditor);
const snippetText = new vscode.SnippetTextEdit(new vscode.Range(1, 3, 1, 3), new vscode.SnippetString('This is line 2\n This is line 3'));
snippetText.keepWhitespace = true;
const we = new vscode.WorkspaceEdit();
we.set(document.uri, [snippetText]);
const success = await vscode.workspace.applyEdit(we);
if (edt !== vscode.window.activeTextEditor) {
return this.skip();
}
assert.ok(success);
assert.strictEqual(document.getText(), 'This is line 1\n This is line 2\n This is line 3');
});
test('Support creating binary files in a WorkspaceEdit', async function (): Promise<any> {
const fileUri = vscode.Uri.parse(`${testFs.scheme}:/${rndName()}`);