| 213 | |
| 214 | // set activeRegexIndices near the latest selection |
| 215 | static updateActiveRegexIndices() { |
| 216 | let activeNodeIndex = -1; |
| 217 | const matchedNodes = this.query.regexMatchedNodes; |
| 218 | const selection = globalThis.getSelection(); |
| 219 | if (selection.rangeCount > 0) { |
| 220 | activeNodeIndex = matchedNodes.indexOf(selection.anchorNode); |
| 221 | |
| 222 | if (activeNodeIndex === -1) { |
| 223 | activeNodeIndex = this.query.regexMatchedNodes.findIndex((node) => { |
| 224 | const range = selection.getRangeAt(0); |
| 225 | |
| 226 | if (range) { |
| 227 | let sourceRange = document.createRange(); |
| 228 | sourceRange.setStart(node, 0); |
| 229 | return range.compareBoundaryPoints(Range.START_TO_START, sourceRange) <= 0; |
| 230 | } else { |
| 231 | return false; |
| 232 | } |
| 233 | }); |
| 234 | } |
| 235 | } |
| 236 | this.query.activeRegexIndices = [Math.max(activeNodeIndex, 0), 0]; |
| 237 | } |
| 238 | |
| 239 | static getQueryFromRegexMatches() { |
| 240 | // find()ing an empty query always returns false |