Skip to content

Commit 8cd47bb

Browse files
committed
Fixes microsoft#6281: Do not truncate line number, column in position
1 parent de77d32 commit 8cd47bb

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

extensions/vscode-api-tests/src/editor.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import * as assert from 'assert';
99
import * as fs from 'fs';
1010
import * as os from 'os';
11-
import {workspace, window, Position} from 'vscode';
11+
import {workspace, window, Position, Range} from 'vscode';
1212
import {createRandomFile, deleteFile, cleanUp} from './utils';
1313
import {join} from 'path';
1414

@@ -38,4 +38,27 @@ suite("editor tests", () => {
3838
});
3939
});
4040
});
41+
42+
test('issue #6281: Edits fail to validate ranges correctly before applying', () => {
43+
return createRandomFile('Hello world!').then(file => {
44+
return workspace.openTextDocument(file).then(doc => {
45+
return window.showTextDocument(doc).then((editor) => {
46+
return editor.edit((builder) => {
47+
builder.replace(new Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE), 'new');
48+
}).then(applied => {
49+
assert.ok(applied);
50+
assert.equal(doc.getText(), 'new');
51+
assert.ok(doc.isDirty);
52+
53+
return doc.save().then(saved => {
54+
assert.ok(saved);
55+
assert.ok(!doc.isDirty);
56+
57+
return deleteFile(file);
58+
});
59+
});
60+
});
61+
});
62+
});
63+
});
4164
});

src/vs/editor/common/core/position.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class Position implements IEditorPosition {
1212
public column: number;
1313

1414
constructor(lineNumber: number, column: number) {
15-
this.lineNumber = lineNumber|0;
16-
this.column = column|0;
15+
this.lineNumber = lineNumber;
16+
this.column = column;
1717
}
1818

1919
public equals(other:IPosition): boolean {

0 commit comments

Comments
 (0)