Skip to content

Commit b05d8f3

Browse files
committed
1 parent 73b5307 commit b05d8f3

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/vs/editor/common/model/wordHelper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ export function getWordAtText(column: number, wordDefinition: RegExp, text: stri
9393
// should stop so that subsequent search don't repeat previous searches
9494
const regexIndex = pos - config.windowSize * i;
9595
wordDefinition.lastIndex = Math.max(0, regexIndex);
96-
match = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex);
96+
const thisMatch = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex);
9797

98-
// stop: found something
99-
if (match) {
98+
if (!thisMatch && match) {
99+
// stop: we have something
100100
break;
101101
}
102102

103+
match = thisMatch;
104+
103105
// stop: searched at start
104106
if (regexIndex <= 0) {
105107
break;
@@ -111,7 +113,7 @@ export function getWordAtText(column: number, wordDefinition: RegExp, text: stri
111113
let result = {
112114
word: match[0],
113115
startColumn: textOffset + 1 + match.index!,
114-
endColumn: textOffset + 1 + wordDefinition.lastIndex
116+
endColumn: textOffset + 1 + match.index! + match[0].length
115117
};
116118
wordDefinition.lastIndex = 0;
117119
return result;

src/vs/workbench/test/browser/api/extHostDocumentData.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,22 @@ suite('ExtHostDocumentData', () => {
315315
assert.ok(range.contains(pos));
316316
assert.equal(data.document.getText(range), 'TaskDefinition');
317317
});
318+
319+
test('Rename popup sometimes populates with text on the left side omitted #96013', function () {
320+
321+
const regex = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
322+
const line = 'int abcdefhijklmnopqwvrstxyz;';
323+
324+
data = new ExtHostDocumentData(undefined!, URI.file(''), [
325+
line
326+
], '\n', 'text', 1, false);
327+
328+
let range = data.document.getWordRangeAtPosition(new Position(0, 27), regex)!;
329+
assert.equal(range.start.line, 0);
330+
assert.equal(range.end.line, 0);
331+
assert.equal(range.start.character, 4);
332+
assert.equal(range.end.character, 28);
333+
});
318334
});
319335

320336
enum AssertDocumentLineMappingDirection {

0 commit comments

Comments
 (0)