Merge from vscode 777931080477e28b7c27e8f7d4b0d69897945946 (#9220)

This commit is contained in:
Anthony Dresser
2020-02-19 22:27:53 -08:00
committed by GitHub
parent ab6fb810f8
commit 0cec223301
115 changed files with 1431 additions and 1133 deletions

View File

@@ -2880,6 +2880,33 @@ suite('Editor Controller - Cursor Configuration', () => {
model.dispose();
});
test('issue #90973: Undo brings back model alternative version', () => {
let model = createTextModel(
[
''
].join('\n'),
{
insertSpaces: false,
}
);
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
const beforeVersion = model.getVersionId();
const beforeAltVersion = model.getAlternativeVersionId();
cursorCommand(cursor, H.Type, { text: 'Hello' }, 'keyboard');
cursorCommand(cursor, H.Undo, {});
const afterVersion = model.getVersionId();
const afterAltVersion = model.getAlternativeVersionId();
assert.notEqual(beforeVersion, afterVersion);
assert.equal(beforeAltVersion, afterAltVersion);
});
model.dispose();
});
});
suite('Editor Controller - Indentation Rules', () => {

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IRange } from 'vs/editor/common/core/range';
import { Selection, ISelection } from 'vs/editor/common/core/selection';
import { ICommand, Handler, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
import { TextModel } from 'vs/editor/common/model/textModel';
@@ -50,7 +50,7 @@ export function testCommand(
export function getEditOperation(model: ITextModel, command: ICommand): IIdentifiedSingleEditOperation[] {
let operations: IIdentifiedSingleEditOperation[] = [];
let editOperationBuilder: IEditOperationBuilder = {
addEditOperation: (range: Range, text: string, forceMoveMarkers: boolean = false) => {
addEditOperation: (range: IRange, text: string, forceMoveMarkers: boolean = false) => {
operations.push({
range: range,
text: text,
@@ -58,7 +58,7 @@ export function getEditOperation(model: ITextModel, command: ICommand): IIdentif
});
},
addTrackedEditOperation: (range: Range, text: string, forceMoveMarkers: boolean = false) => {
addTrackedEditOperation: (range: IRange, text: string, forceMoveMarkers: boolean = false) => {
operations.push({
range: range,
text: text,
@@ -67,7 +67,7 @@ export function getEditOperation(model: ITextModel, command: ICommand): IIdentif
},
trackSelection: (selection: Selection) => {
trackSelection: (selection: ISelection) => {
return '';
}
};

View File

@@ -5,7 +5,7 @@
import { CharCode } from 'vs/base/common/charCode';
import { Range } from 'vs/editor/common/core/range';
import { DefaultEndOfLine, IIdentifiedSingleEditOperation, ITextBuffer, ITextBufferBuilder } from 'vs/editor/common/model';
import { DefaultEndOfLine, ITextBuffer, ITextBufferBuilder, ValidAnnotatedEditOperation } from 'vs/editor/common/model';
export function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
@@ -31,7 +31,7 @@ export function getRandomString(minLength: number, maxLength: number): string {
return r;
}
export function generateRandomEdits(chunks: string[], editCnt: number): IIdentifiedSingleEditOperation[] {
export function generateRandomEdits(chunks: string[], editCnt: number): ValidAnnotatedEditOperation[] {
let lines: string[] = [];
for (const chunk of chunks) {
let newLines = chunk.split(/\r\n|\r|\n/);
@@ -43,7 +43,7 @@ export function generateRandomEdits(chunks: string[], editCnt: number): IIdentif
}
}
let ops: IIdentifiedSingleEditOperation[] = [];
let ops: ValidAnnotatedEditOperation[] = [];
for (let i = 0; i < editCnt; i++) {
let line = getRandomInt(1, lines.length);
@@ -54,17 +54,14 @@ export function generateRandomEdits(chunks: string[], editCnt: number): IIdentif
text = getRandomString(5, 10);
}
ops.push({
text: text,
range: new Range(line, startColumn, line, endColumn)
});
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, startColumn, line, endColumn), text, false, false, false));
lines[line - 1] = lines[line - 1].substring(0, startColumn - 1) + text + lines[line - 1].substring(endColumn - 1);
}
return ops;
}
export function generateSequentialInserts(chunks: string[], editCnt: number): IIdentifiedSingleEditOperation[] {
export function generateSequentialInserts(chunks: string[], editCnt: number): ValidAnnotatedEditOperation[] {
let lines: string[] = [];
for (const chunk of chunks) {
let newLines = chunk.split(/\r\n|\r|\n/);
@@ -76,7 +73,7 @@ export function generateSequentialInserts(chunks: string[], editCnt: number): II
}
}
let ops: IIdentifiedSingleEditOperation[] = [];
let ops: ValidAnnotatedEditOperation[] = [];
for (let i = 0; i < editCnt; i++) {
let line = lines.length;
@@ -90,16 +87,13 @@ export function generateSequentialInserts(chunks: string[], editCnt: number): II
lines[line - 1] += text;
}
ops.push({
text: text,
range: new Range(line, column, line, column)
});
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, column, line, column), text, false, false, false));
}
return ops;
}
export function generateRandomReplaces(chunks: string[], editCnt: number, searchStringLen: number, replaceStringLen: number): IIdentifiedSingleEditOperation[] {
export function generateRandomReplaces(chunks: string[], editCnt: number, searchStringLen: number, replaceStringLen: number): ValidAnnotatedEditOperation[] {
let lines: string[] = [];
for (const chunk of chunks) {
let newLines = chunk.split(/\r\n|\r|\n/);
@@ -111,7 +105,7 @@ export function generateRandomReplaces(chunks: string[], editCnt: number, search
}
}
let ops: IIdentifiedSingleEditOperation[] = [];
let ops: ValidAnnotatedEditOperation[] = [];
let chunkSize = Math.max(1, Math.floor(lines.length / editCnt));
let chunkCnt = Math.floor(lines.length / chunkSize);
let replaceString = getRandomString(replaceStringLen, replaceStringLen);
@@ -125,10 +119,7 @@ export function generateRandomReplaces(chunks: string[], editCnt: number, search
let startColumn = getRandomInt(1, maxColumn);
let endColumn = Math.min(maxColumn, startColumn + searchStringLen);
ops.push({
text: replaceString,
range: new Range(line, startColumn, line, endColumn)
});
ops.push(new ValidAnnotatedEditOperation(null, new Range(line, startColumn, line, endColumn), replaceString, false, false, false));
previousChunksLength = endLine;
}
@@ -166,4 +157,4 @@ export function generateRandomChunkWithLF(minLength: number, maxLength: number):
}
}
return r;
}
}