提交 3f205ed5 编写于 作者: A Alex Dima

Fixes #44870: use replace-move semantics to avoid expanding selection

上级 6e1f737a
......@@ -46,7 +46,7 @@ export class EditOperationsCommand implements editorCommon.ICommand {
static execute(editor: ICodeEditor, _edits: TextEdit[]) {
let edits = this._handleEolEdits(editor, _edits);
editor.pushUndoStop();
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
editor.pushUndoStop();
}
......
......@@ -11,6 +11,7 @@ import { ISingleEditOperation } from 'vs/editor/common/model';
import { TextModel } from 'vs/editor/common/model/textModel';
import { EditOperationsCommand } from 'vs/editor/contrib/format/formatCommand';
import { testCommand } from 'vs/editor/test/browser/testCommand';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
function editOp(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, text: string[]): ISingleEditOperation {
return {
......@@ -310,4 +311,27 @@ suite('FormatCommand', () => {
);
});
test('issue #44870', () => {
const initialText = [
'[',
' {},{',
' }',
']',
];
withTestCodeEditor(initialText, {}, (editor) => {
editor.setSelection(new Selection(2, 8, 2, 8));
EditOperationsCommand.execute(editor, [
editOp(2, 8, 2, 8, ['', ' ']),
editOp(2, 9, 3, 5, ['']),
]);
assert.equal(editor.getValue(), [
'[',
' {},',
' {}',
']',
].join('\n'));
assert.deepEqual(editor.getSelection(), new Selection(3, 5, 3, 5));
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册