Skip to content

Commit a811707

Browse files
committed
Fixes microsoft#48046: Skip over a word made up of one single separator and followed by a regular character
1 parent 2546254 commit a811707

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ export class WordOperations {
171171
let prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, column));
172172

173173
if (wordNavigationType === WordNavigationType.WordStart) {
174+
if (prevWordOnLine && prevWordOnLine.wordType === WordType.Separator) {
175+
if (prevWordOnLine.end - prevWordOnLine.start === 1 && prevWordOnLine.nextCharClass === WordCharacterClass.Regular) {
176+
// Skip over a word made up of one single separator and followed by a regular character
177+
prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, prevWordOnLine.start + 1));
178+
}
179+
}
174180
if (prevWordOnLine) {
175181
column = prevWordOnLine.start + 1;
176182
} else {

src/vs/editor/contrib/wordOperations/test/wordOperations.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ suite('WordOperations', () => {
141141
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002');
142142
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003');
143143
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004');
144-
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005');
145144
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006');
146145
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007');
147146
moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008');
@@ -165,7 +164,6 @@ suite('WordOperations', () => {
165164
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002');
166165
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003');
167166
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004');
168-
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005');
169167
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006');
170168
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007');
171169
moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008');
@@ -290,6 +288,18 @@ suite('WordOperations', () => {
290288
});
291289
});
292290

291+
test('issue #48046: Word selection doesn\'t work as usual', () => {
292+
withTestCodeEditor([
293+
'deep.object.property'
294+
], {}, (editor, _) => {
295+
editor.setPosition(new Position(1, 21));
296+
297+
moveWordLeft(editor); assert.equal(editor.getPosition().column, 'deep.object.'.length + 1, '001');
298+
moveWordLeft(editor); assert.equal(editor.getPosition().column, 'deep.'.length + 1, '002');
299+
moveWordLeft(editor); assert.equal(editor.getPosition().column, ''.length + 1, '003');
300+
});
301+
});
302+
293303
test('moveWordEndRight', () => {
294304
withTestCodeEditor([
295305
' /* Just some more text a+= 3 +5-3 + 7 */ '

0 commit comments

Comments
 (0)