| 90 | } |
| 91 | |
| 92 | function getWordAtPosSlow( |
| 93 | column: number, |
| 94 | wordDefinition: RegExp, |
| 95 | text: string, |
| 96 | textOffset: number |
| 97 | ): IWordAtPosition | null { |
| 98 | // matches all words starting at the beginning |
| 99 | // of the input until it finds a match that encloses |
| 100 | // the desired column. slow but correct |
| 101 | |
| 102 | const pos = column - 1 - textOffset; |
| 103 | wordDefinition.lastIndex = 0; |
| 104 | |
| 105 | let match: RegExpMatchArray | null = wordDefinition.exec(text); |
| 106 | while (match) { |
| 107 | const matchIndex = match.index || 0; |
| 108 | if (matchIndex > pos) { |
| 109 | // |nW -> matched only after the pos |
| 110 | return null; |
| 111 | } else if (wordDefinition.lastIndex >= pos) { |
| 112 | // W|W -> match encloses pos |
| 113 | return { |
| 114 | word: match[0], |
| 115 | startColumn: textOffset + 1 + matchIndex, |
| 116 | endColumn: textOffset + 1 + wordDefinition.lastIndex |
| 117 | }; |
| 118 | } |
| 119 | match = wordDefinition.exec(text); |
| 120 | } |
| 121 | |
| 122 | return null; |
| 123 | } |
| 124 | |
| 125 | export function getWordAtText( |
| 126 | column: number, |