mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
fix: return last found index even if fewer than n instances found, instead of undefined
This commit is contained in:
parent
7ca0e78ebc
commit
5215915014
1 changed files with 3 additions and 2 deletions
|
|
@ -47,12 +47,13 @@ function getNthNextInstanceOfPattern({
|
|||
}): number {
|
||||
const globalRegex = makeGlobalRegex(regex);
|
||||
globalRegex.lastIndex = startingIdx + 1;
|
||||
let currMatch;
|
||||
let currMatch, lastMatch;
|
||||
let numMatchesFound = 0;
|
||||
while (numMatchesFound < n && (currMatch = globalRegex.exec(content)) != null) {
|
||||
lastMatch = currMatch;
|
||||
numMatchesFound++;
|
||||
}
|
||||
return currMatch?.index;
|
||||
return lastMatch?.index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue