| 62 | } |
| 63 | |
| 64 | function getWordAtPosFast( |
| 65 | column: number, |
| 66 | wordDefinition: RegExp, |
| 67 | text: string, |
| 68 | textOffset: number |
| 69 | ): IWordAtPosition | null { |
| 70 | // find whitespace enclosed text around column and match from there |
| 71 | |
| 72 | const pos = column - 1 - textOffset; |
| 73 | const start = text.lastIndexOf(' ', pos - 1) + 1; |
| 74 | |
| 75 | wordDefinition.lastIndex = start; |
| 76 | let match: RegExpMatchArray | null = wordDefinition.exec(text); |
| 77 | while (match) { |
| 78 | const matchIndex = match.index || 0; |
| 79 | if (matchIndex <= pos && wordDefinition.lastIndex >= pos) { |
| 80 | return { |
| 81 | word: match[0], |
| 82 | startColumn: textOffset + 1 + matchIndex, |
| 83 | endColumn: textOffset + 1 + wordDefinition.lastIndex |
| 84 | }; |
| 85 | } |
| 86 | match = wordDefinition.exec(text); |
| 87 | } |
| 88 | |
| 89 | return null; |
| 90 | } |
| 91 | |
| 92 | function getWordAtPosSlow( |
| 93 | column: number, |