116
return getWordAtText(column, wordDefinition, text, textOffset, config);
117
}
119
>
const t1 = Date.now();
120
>
const pos = column - 1 - textOffset;
121
>
122
>
let prevRegexIndex = -1;
123
>
let match: RegExpExecArray | null = null;
124
>
125
>
for (let i = 1; ; i++) {
126
>
// check time budget
127
>
if (Date.now() - t1 >= config.timeBudget) {
128
break;
129
}
131
>
// reset the index at which the regexp should start matching, also know where it
132
>
// should stop so that subsequent search don't repeat previous searches
133
>
const regexIndex = pos - config.windowSize * i;
134
>
wordDefinition.lastIndex = Math.max(0, regexIndex);
135
>
const thisMatch = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex);
136
>
137
>
if (!thisMatch && match) {
138
// stop: we have something
139
break;
140
}
142
>
match = thisMatch;
143
>
144
>
// stop: searched at start
145
>
if (regexIndex <= 0) {
146
>
break;
147
>
}
148
prevRegexIndex = regexIndex;
149
}
151
>
if (match) {
152
const result = {
153
word: match[0],