replaceNext no longer advances to the next match after replacing (regression in @codemirror/search 6.7.0)
After upgrading @codemirror/search from 6.6.0 to 6.7.0, the “Replace” button requires two clicks per match: the first click only re-selects the current match instead of replacing-and-advancing.
The cause looks like a dropped line in replaceNext. In 6.6.0 the replace branch advances the selection to the next match:
if (next.from == from && next.to == to) {
replacement = state.toText(query.getReplacement(next));
changes.push({ from: next.from, to: next.to, insert: replacement });
next = query.nextMatch(state, next.from, next.to); // advances to next match
effects.push(...);
}
In 6.7.0 that line is gone, so after a replacement the selection stays on the just-inserted text instead of moving to the next match:
if (!next.precise) {
next = query.nextMatch(state, next.from, next.to);
} else if (next.from == from && next.to == to) {
replacement = state.toText(query.getReplacement(next));
changes.push({ from: next.from, to: next.to, insert: replacement });
// no `next = query.nextMatch(...)` here
}
Repro: open a search/replace panel on text like select * from public.user;, search e, replace _, click “Replace” repeatedly — each replacement takes two clicks instead of one.
Reverting to 6.6.0 fixes it.