({
cm,
cursorPosition,
repeat,
regex,
filterMatch = () => true,
direction,
}: {
cm: CodeMirrorEditor;
cursorPosition: EditorPosition;
repeat: number;
regex: RegExp;
filterMatch?: (match: RegExpExecArray) => boolean;
direction: "next" | "previous";
})
| 20 | * @param direction The direction to jump in. |
| 21 | */ |
| 22 | export function jumpToPattern({ |
| 23 | cm, |
| 24 | cursorPosition, |
| 25 | repeat, |
| 26 | regex, |
| 27 | filterMatch = () => true, |
| 28 | direction, |
| 29 | }: { |
| 30 | cm: CodeMirrorEditor; |
| 31 | cursorPosition: EditorPosition; |
| 32 | repeat: number; |
| 33 | regex: RegExp; |
| 34 | filterMatch?: (match: RegExpExecArray) => boolean; |
| 35 | direction: "next" | "previous"; |
| 36 | }): EditorPosition { |
| 37 | const content = cm.getValue(); |
| 38 | const cursorIdx = cm.indexFromPos(cursorPosition); |
| 39 | const orderedMatches = getOrderedMatches({ content, regex, cursorIdx, filterMatch, direction }); |
| 40 | const effectiveRepeat = (repeat % orderedMatches.length) || orderedMatches.length; |
| 41 | const matchIdx = orderedMatches[effectiveRepeat - 1]?.index; |
| 42 | if (matchIdx === undefined) { |
| 43 | return cursorPosition; |
| 44 | } |
| 45 | const newCursorPosition = cm.posFromIndex(matchIdx); |
| 46 | return newCursorPosition; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns an ordered array of all matches of a regex in a string in the given direction from the |
no test coverage detected