Skip to content

Commit 8e1402b

Browse files
committed
Fixes microsoft#33788: Wrong cursor position when double click to select a word
1 parent 9418ba5 commit 8e1402b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/vs/editor/common/controller/cursorWordOperations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ export class WordOperations {
425425

426426
let lineNumber = position.lineNumber;
427427
let column: number;
428-
if (position.isBeforeOrEqual(cursor.selectionStart.getStartPosition())) {
428+
if (cursor.selectionStart.containsPosition(position)) {
429+
column = cursor.selectionStart.endColumn;
430+
} else if (position.isBeforeOrEqual(cursor.selectionStart.getStartPosition())) {
429431
column = startColumn;
430432
let possiblePosition = new Position(lineNumber, column);
431433
if (cursor.selectionStart.containsPosition(possiblePosition)) {

src/vs/editor/test/common/controller/cursor.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,24 @@ suite('Editor Controller - Regression tests', () => {
16291629
});
16301630
});
16311631

1632+
test('issue #33788: Wrong cursor position when double click to select a word', () => {
1633+
let model = Model.createFromString(
1634+
[
1635+
'Just some text'
1636+
].join('\n')
1637+
);
1638+
1639+
withMockCodeEditor(null, { model: model }, (editor, cursor) => {
1640+
CoreNavigationCommands.WordSelect.runCoreEditorCommand(cursor, { position: new Position(1, 8) });
1641+
assert.deepEqual(cursor.getSelection(), new Selection(1, 6, 1, 10));
1642+
1643+
CoreNavigationCommands.WordSelectDrag.runCoreEditorCommand(cursor, { position: new Position(1, 8) });
1644+
assert.deepEqual(cursor.getSelection(), new Selection(1, 6, 1, 10));
1645+
});
1646+
1647+
model.dispose();
1648+
});
1649+
16321650
test('issue #9675: Undo/Redo adds a stop in between CHN Characters', () => {
16331651
usingCursor({
16341652
text: [

0 commit comments

Comments
 (0)