Skip to content

Find and Replace on selected text inserts duplicates when using capture groups

Environment:
reproduced with mousepad version 0.5.0-1 on manajaro installed via package manager and with mousepad built from master@110221c2 on the same machine

How to reproduce

text file content:

UP               no-osd seek  3
DOWN             no-osd seek -3
Shift+UP         no-osd seek  10
Shift+DOWN       no-osd seek -10
Ctrl+UP          no-osd seek  60
Ctrl+DOWN        no-osd seek -60
Ctrl+Shift+UP    no-osd seek  300
Ctrl+Shift+DOWN  no-osd seek -300
  • Open with mousepad. Press Ctrl+R for Find & Replace dialog.

  • Put Search for: ([0-9]+) or (3) for example

  • Put Replace with: \1 exact. Try exact to see bahavior without capture group.

  • Tick only Regular expression and Replace all in, choose Selection from drop-down. Try Document to see desired behavior.

  • Select text in document & press Replace All

Expected behavior:

transformed text:

UP               no-osd seek  3 exact
DOWN             no-osd seek -3 exact
Shift+UP         no-osd seek  10 exact
Shift+DOWN       no-osd seek -10 exact
Ctrl+UP          no-osd seek  60 exact
Ctrl+DOWN        no-osd seek -60 exact
Ctrl+Shift+UP    no-osd seek  300 exact
Ctrl+Shift+DOWN  no-osd seek -300 exact

Observed behavior:

transformed text:

UP               no-osd seek  3 exact exact
DOWN             no-osd seek -3 exact exact
Shift+UP         no-osd seek  10 exact exact
Shift+DOWN       no-osd seek -10 exact exact
Ctrl+UP          no-osd seek  60 exact exact
Ctrl+DOWN        no-osd seek -60 exact exact
Ctrl+Shift+UP    no-osd seek  300 exact exact
Ctrl+Shift+DOWN  no-osd seek -300 exact exact