This commit is contained in:
Johannes Rieken 2018-07-26 19:10:58 +02:00
parent 4c5c94185f
commit 9cc1fc914d
2 changed files with 29 additions and 4 deletions

View file

@ -497,6 +497,11 @@ export class ExtHostTextEditor implements vscode.TextEditor {
private _applyEdit(editBuilder: TextEditorEdit): TPromise<boolean> {
let editData = editBuilder.finalize();
// return when there is nothing to do
if (editData.edits.length === 0 && !editData.setEndOfLine) {
return TPromise.wrap(true);
}
// check that the edits are not overlapping (i.e. illegal)
let editRanges = editData.edits.map(edit => edit.range);

View file

@ -6,21 +6,22 @@
import * as assert from 'assert';
import { TPromise } from 'vs/base/common/winjs.base';
import { TextEditorLineNumbersStyle } from 'vs/workbench/api/node/extHostTypes';
import { TextEditorLineNumbersStyle, Range } from 'vs/workbench/api/node/extHostTypes';
import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
import { MainThreadTextEditorsShape, IResolvedTextEditorConfiguration, ITextEditorConfigurationUpdate } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostTextEditorOptions, ExtHostTextEditor } from 'vs/workbench/api/node/extHostTextEditor';
import { ExtHostDocumentData } from 'vs/workbench/api/node/extHostDocumentData';
import URI from 'vs/base/common/uri';
import { mock } from 'vs/workbench/test/electron-browser/api/mock';
suite('ExtHostTextEditor', () => {
let editor: ExtHostTextEditor;
let doc = new ExtHostDocumentData(undefined, URI.file(''), [
'aaaa bbbb+cccc abc'
], '\n', 'text', 1, false);
setup(() => {
let doc = new ExtHostDocumentData(undefined, URI.file(''), [
'aaaa bbbb+cccc abc'
], '\n', 'text', 1, false);
editor = new ExtHostTextEditor(null, 'fake', doc, [], { cursorStyle: 0, insertSpaces: true, lineNumbers: 1, tabSize: 4 }, [], 1);
});
@ -39,6 +40,25 @@ suite('ExtHostTextEditor', () => {
assert.throws(() => editor._acceptOptions(null));
assert.throws(() => editor._acceptSelections([]));
});
test('API [bug]: registerTextEditorCommand clears redo stack even if no edits are made #55163', async function () {
let applyCount = 0;
let editor = new ExtHostTextEditor(new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyEdits(): TPromise<boolean> {
applyCount += 1;
return TPromise.wrap(true);
}
}, 'edt1', doc, [], { cursorStyle: 0, insertSpaces: true, lineNumbers: 1, tabSize: 4 }, [], 1);
await editor.edit(edit => { });
assert.equal(applyCount, 0);
await editor.edit(edit => { edit.setEndOfLine(1); });
assert.equal(applyCount, 1);
await editor.edit(edit => { edit.delete(new Range(0, 0, 1, 1)); });
assert.equal(applyCount, 2);
});
});
suite('ExtHostTextEditorOptions', () => {