pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

"Replace All" with `$` replacement sometimes gets the replacement wrong

Open danfuzz opened this issue 1 year ago • 2 comments
trafficstars

Thanks in advance for your bug report!

  • [X] Have you reproduced issue in safe mode?
  • [X] Have you used the debugging guide to try to resolve the issue?
  • [X] Have you checked our FAQs to make sure your question isn't answered there?
  • [X] Have you checked to make sure your issue does not already exist?
  • [X] Have you checked you are on the latest release of Pulsar?

What happened?

"Replace all" with match group replacement ($N) sometimes uses the wrong matching string. I'm not entirely sure what triggers it, and, for example, I'll sometimes see that within a single "replace all" action, some replacements will be right and some will be wrong.

For example, I recently tried to replace \b_impl_serverSocket(Start|Stop)\b with _impl_socket$1 using "replace all." Of the three files that were affected, one was correct, and the other two had diffs like this:

     // the application might need to see the server stopping _and_ vice versa.
     await Promise.all([
-      this._impl_serverSocketStop(this.#reloading),
+      this._impl_socketStart(this.#reloading),
       this._impl_applicationStop(this.#reloading)

Pulsar version

1.114.0

Which OS does this happen on?

🍎 macOS

OS details

13.6.3

Which CPU architecture are you running this on?

ARM64/AArch64

What steps are needed to reproduce this?

  1. Have some files in a project with contents that are amenable to a match group replacement.
  2. "Find All."
  3. Write a pattern to find like prefix(Option1|Option2).
  4. Write a replacement like newPrefix$1.
  5. Find all!
  6. Replace all!

Note that some of the replacements are wrong.

Additional Information:

When you look at the preview for replacements in these cases (in the search results window), the preview looks correct.

danfuzz avatar Mar 04 '24 19:03 danfuzz

I tried to reproduce this issue and maybe I found a workaround.

First, write the pattern without capturing groups:

Schermata del 2024-05-16 09-06-21

Start the search in project. You should see all the results. Then add the capturing group and type the replacement. The group is not replaced correctly, indeed $1 is shown in the preview:

Schermata del 2024-05-16 09-07-55

To workaround this issue, just restart the search clicking on Find all. Now the previews are correct.

Schermata del 2024-05-16 09-08-11

Replace All and it works:

Schermata del 2024-05-16 09-09-04

Digitalone1 avatar May 16 '24 07:05 Digitalone1