提交 118e1445 编写于 作者: A Alex Dima

Fixes #46208: Recover selection from markers when the undo/redo stack lacks selection information

上级 4f4dc86a
......@@ -361,7 +361,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
private _interpretCommandResult(cursorState: Selection[]): void {
if (!cursorState || cursorState.length === 0) {
return;
cursorState = this._cursors.readSelectionFromMarkers();
}
this._columnSelectData = null;
......
......@@ -13,7 +13,6 @@ import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { TextModel, createTextBuffer } from 'vs/editor/common/model/textModel';
import { IMode, LanguageIdentifier } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -398,9 +397,9 @@ export class ModelServiceImpl implements IModelService {
// Otherwise find a diff between the values and update model
model.setEOL(textBuffer.getEOL() === '\r\n' ? EndOfLineSequence.CRLF : EndOfLineSequence.LF);
model.pushEditOperations(
[new Selection(1, 1, 1, 1)],
[],
ModelServiceImpl._computeEdits(model, textBuffer),
(inverseEditOperations: IIdentifiedSingleEditOperation[]) => [new Selection(1, 1, 1, 1)]
(inverseEditOperations: IIdentifiedSingleEditOperation[]) => []
);
}
......@@ -451,7 +450,7 @@ export class ModelServiceImpl implements IModelService {
newRange = new Range(1, 1, textBufferLineCount, 1 + textBuffer.getLineLength(textBufferLineCount));
}
return [EditOperation.replace(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
return [EditOperation.replaceMove(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
}
public createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI, isForSimpleWidget: boolean = false): ITextModel {
......
......@@ -1219,6 +1219,64 @@ suite('Editor Controller - Regression tests', () => {
model.dispose();
});
test('issue #46208: Allow empty selections in the undo/redo stack', () => {
let model = TextModel.createFromString('');
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
cursorCommand(cursor, H.Type, { text: 'Hello' }, 'keyboard');
cursorCommand(cursor, H.Type, { text: ' ' }, 'keyboard');
cursorCommand(cursor, H.Type, { text: 'world' }, 'keyboard');
cursorCommand(cursor, H.Type, { text: ' ' }, 'keyboard');
assert.equal(model.getLineContent(1), 'Hello world ');
assertCursor(cursor, new Position(1, 13));
moveLeft(cursor);
moveRight(cursor);
model.pushEditOperations([], [EditOperation.replaceMove(new Range(1, 12, 1, 13), '')], () => []);
assert.equal(model.getLineContent(1), 'Hello world');
assertCursor(cursor, new Position(1, 12));
cursorCommand(cursor, H.Undo, {});
assert.equal(model.getLineContent(1), 'Hello world ');
assertCursor(cursor, new Position(1, 13));
cursorCommand(cursor, H.Undo, {});
assert.equal(model.getLineContent(1), 'Hello world');
assertCursor(cursor, new Position(1, 12));
cursorCommand(cursor, H.Undo, {});
assert.equal(model.getLineContent(1), 'Hello');
assertCursor(cursor, new Position(1, 6));
cursorCommand(cursor, H.Undo, {});
assert.equal(model.getLineContent(1), '');
assertCursor(cursor, new Position(1, 1));
cursorCommand(cursor, H.Redo, {});
assert.equal(model.getLineContent(1), 'Hello');
assertCursor(cursor, new Position(1, 6));
cursorCommand(cursor, H.Redo, {});
assert.equal(model.getLineContent(1), 'Hello world');
assertCursor(cursor, new Position(1, 12));
cursorCommand(cursor, H.Redo, {});
assert.equal(model.getLineContent(1), 'Hello world ');
assertCursor(cursor, new Position(1, 13));
cursorCommand(cursor, H.Redo, {});
assert.equal(model.getLineContent(1), 'Hello world');
assertCursor(cursor, new Position(1, 12));
cursorCommand(cursor, H.Redo, {});
assert.equal(model.getLineContent(1), 'Hello world');
assertCursor(cursor, new Position(1, 12));
});
model.dispose();
});
test('bug #16815:Shift+Tab doesn\'t go back to tabstop', () => {
let mode = new OnEnterMode(IndentAction.IndentOutdent);
let model = TextModel.createFromString(
......
......@@ -50,7 +50,7 @@ class TrimWhitespaceParticipant implements ISaveParticipantParticipant {
}
private doTrimTrailingWhitespace(model: ITextModel, isAutoSaved: boolean): void {
let prevSelection: Selection[] = [new Selection(1, 1, 1, 1)];
let prevSelection: Selection[] = [];
const cursors: Position[] = [];
let editor = findEditor(model, this.codeEditorService);
......@@ -114,7 +114,7 @@ export class FinalNewLineParticipant implements ISaveParticipantParticipant {
return;
}
let prevSelection: Selection[] = [new Selection(1, 1, 1, 1)];
let prevSelection: Selection[] = [];
const editor = findEditor(model, this.codeEditorService);
if (editor) {
prevSelection = editor.getSelections();
......@@ -151,7 +151,7 @@ export class TrimFinalNewLinesParticipant implements ISaveParticipantParticipant
return;
}
let prevSelection: Selection[] = [new Selection(1, 1, 1, 1)];
let prevSelection: Selection[] = [];
const editor = findEditor(model, this.codeEditorService);
if (editor) {
prevSelection = editor.getSelections();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册