Search replaceNext() does not update selection correctly when regexp option is used

Repro steps:

  1. Open the stock demo at Try CodeMirror
  2. Add the output:
* [[Help:Foo|Barrrrrrrrrrr]]
* [[Help:Bazzzz|Qux]]
* [[Help:Qux|Fooo]]
* [[Help:Barrrrrr|Baz]]
  1. Open the search dialog and use the query \[\[Help:(.*)\|(.*)\]\] with the “regexp” option checked
  2. Use the replacement text {{Help|$1|$2}}
  3. Hit the “replace” button four times

Expected:

After each replacement, the next match should be highlighted, and clicking “replace” again should replace that match. Four clicks in this example should replace all four lines like so:

* {{Help|Foo|Barrrrrrrrrrr}}
* {{Help|Bazzzz|Qux}}
* {{Help|Qux|Fooo}}
* {{Help|Barrrrrr|Baz}}

Observed:

CodeMirror apparently does not take into account the changes to the document as a result of the replacement. You have to click “replace” repeatedly to force a new match, and since the cursor/selection was not correctly updated, the next occurrence will be the third line and not the second line.

I.e. the four clicks produce:

* {{Help|Foo|Barrrrrrrrrrr}}
* [[Help:Bazzzz|Qux]]
* {{Help|Qux|Fooo}}
* [[Help:Barrrrrr|Baz]]

This patch should help here.

1 Like

Thank you!! :smiley: