mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 08:06:04 +00:00
Merge pull request #5705 from aioutecism/hotfix/validate-position
Fix validatePosition related bug
This commit is contained in:
commit
a3c2088b54
3 changed files with 53 additions and 25 deletions
|
@ -501,17 +501,20 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
|
|||
|
||||
if (lineNumber < 1) {
|
||||
lineNumber = 1;
|
||||
}
|
||||
if (lineNumber > this._lines.length) {
|
||||
lineNumber = this._lines.length;
|
||||
}
|
||||
|
||||
if (column < 1) {
|
||||
column = 1;
|
||||
}
|
||||
var maxColumn = this.getLineMaxColumn(lineNumber);
|
||||
if (column > maxColumn) {
|
||||
column = maxColumn;
|
||||
else if (lineNumber > this._lines.length) {
|
||||
lineNumber = this._lines.length;
|
||||
column = this.getLineMaxColumn(lineNumber);
|
||||
}
|
||||
else {
|
||||
var maxColumn = this.getLineMaxColumn(lineNumber);
|
||||
if (column < 1) {
|
||||
column = 1;
|
||||
}
|
||||
else if (column > maxColumn) {
|
||||
column = maxColumn;
|
||||
}
|
||||
}
|
||||
|
||||
return new Position(lineNumber, column);
|
||||
|
@ -850,4 +853,4 @@ export class RawText {
|
|||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -435,12 +435,36 @@ suite('Editor Model - TextModel', () => {
|
|||
], 'mixed whitespace 2');
|
||||
});
|
||||
|
||||
test('validatePosition', () => {
|
||||
|
||||
var m = new TextModel([], TextModel.toRawText('line one\nline two', TextModel.DEFAULT_CREATION_OPTIONS));
|
||||
|
||||
assert.deepEqual(m.validatePosition(new Position(0, 0)), new Position(1, 1));
|
||||
assert.deepEqual(m.validatePosition(new Position(0, 1)), new Position(1, 1));
|
||||
|
||||
assert.deepEqual(m.validatePosition(new Position(1, 1)), new Position(1, 1));
|
||||
assert.deepEqual(m.validatePosition(new Position(1, 2)), new Position(1, 2));
|
||||
assert.deepEqual(m.validatePosition(new Position(1, 30)), new Position(1, 9));
|
||||
|
||||
assert.deepEqual(m.validatePosition(new Position(2, 0)), new Position(2, 1));
|
||||
assert.deepEqual(m.validatePosition(new Position(2, 1)), new Position(2, 1));
|
||||
assert.deepEqual(m.validatePosition(new Position(2, 2)), new Position(2, 2));
|
||||
assert.deepEqual(m.validatePosition(new Position(2, 30)), new Position(2, 9));
|
||||
|
||||
assert.deepEqual(m.validatePosition(new Position(3, 0)), new Position(2, 9));
|
||||
assert.deepEqual(m.validatePosition(new Position(3, 1)), new Position(2, 9));
|
||||
assert.deepEqual(m.validatePosition(new Position(3, 30)), new Position(2, 9));
|
||||
|
||||
assert.deepEqual(m.validatePosition(new Position(30, 30)), new Position(2, 9));
|
||||
|
||||
});
|
||||
|
||||
test('modifyPosition', () => {
|
||||
|
||||
var m = new TextModel([], TextModel.toRawText('line one\nline two', TextModel.DEFAULT_CREATION_OPTIONS));
|
||||
assert.deepEqual(m.modifyPosition(new Position(1,1), 0), new Position(1, 1));
|
||||
assert.deepEqual(m.modifyPosition(new Position(0,0), 0), new Position(1, 1));
|
||||
assert.deepEqual(m.modifyPosition(new Position(30, 1), 0), new Position(2, 1));
|
||||
assert.deepEqual(m.modifyPosition(new Position(30, 1), 0), new Position(2, 9));
|
||||
|
||||
assert.deepEqual(m.modifyPosition(new Position(1,1), 17), new Position(2, 9));
|
||||
assert.deepEqual(m.modifyPosition(new Position(1,1), 1), new Position(1, 2));
|
||||
|
|
|
@ -395,24 +395,25 @@ export class ExtHostDocumentData extends MirrorModel2 {
|
|||
|
||||
if (line < 0) {
|
||||
line = 0;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
if (line >= this._lines.length) {
|
||||
line = this._lines.length - 1;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
if (character < 0) {
|
||||
character = 0;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
let maxCharacter = this._lines[line].length;
|
||||
if (character > maxCharacter) {
|
||||
character = maxCharacter;
|
||||
else if (line >= this._lines.length) {
|
||||
line = this._lines.length - 1;
|
||||
character = this._lines[line].length;
|
||||
hasChanged = true;
|
||||
}
|
||||
else {
|
||||
let maxCharacter = this._lines[line].length;
|
||||
if (character < 0) {
|
||||
character = 0;
|
||||
hasChanged = true;
|
||||
}
|
||||
else if (character > maxCharacter) {
|
||||
character = maxCharacter;
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasChanged) {
|
||||
return position;
|
||||
|
@ -674,4 +675,4 @@ export class MainThreadDocuments {
|
|||
}
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue