Repository: vscode
Issue: Replace in files is buggy when multiple changes are made on same line of code
Labels: bug,search,confirmed

Type: <b>Bug</b>

Hi,

In the Search in files option, when we try to search (say for 'quantity') & replace (say replace with ORDER_FILLED_QUANTITY), and happen to select multiple instances of the search results with more than 1 instances in the same line of code, and then select replace (by right click), the changes made by the editor are incorrect and happen to misplace the text. It appears changes are being done keeping the original position of the search text in mind, where as in the process of replacing for multiple instances in same line, the position of the 2nd (or later) instances of the search text in the line changes, where as editor seems to replace based on the original position of the search text in the line.

e.g. if the original line is:
my name is 'quantity' and i exist in second place as well like 'quantity' and it's good

In the search in files option if we search for 'quantity' (with single quotes), for the above line 2 instances will get listed in the search results. We mention replace text as ORDER_FILLED_QUANTITY. Now if we select the 2 instances and right click and select Replace, we will see that the 2nd text replacement is misplaced in the line and some other text has got replaced.

VS Code version: Code 1.73.0 (8fa188b2b301d36553cbc9ce1b0a146ccb93351f, 2022-11-01T15:38:50.881Z)
OS version: Darwin x64 21.6.0
Modes:
Sandboxed: No

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz (4 x 1600)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>metal: disabled_off<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: disabled_off|
|Load (avg)|6, 6, 6|
|Memory (System)|8.00GB (0.03GB free)|
|Process Argv|--crash-reporter-id 2c518836-798d-47b7-b16c-e76bc10fa2b8|
|Screen Reader|no|
|VM|0%|
</details><details><summary>Extensions (39)</summary>

Extension|Author (truncated)|Version
---|---|---
vscode-browser-preview|auc|0.7.2
doxdocgen|csc|1.4.0
dart-code|Dar|3.52.1
flutter|Dar|3.52.0
vscode-eslint|dba|2.2.6
es7-react-js-snippets|dsz|4.4.3
gitlens|eam|13.0.4
prettier-vscode|esb|9.9.0
vscode-firefox-debug|fir|2.9.8
auto-rename-tag|for|0.1.10
go|gol|0.36.0
better-cpp-syntax|jef|1.16.3
cmake-language-support-vscode|jos|0.0.7
vscode-docker|ms-|1.22.2
vscode-dotnet-runtime|ms-|1.6.0
isort|ms-|2022.6.0
python|ms-|2022.18.2
vscode-pylance|ms-|2022.11.20
jupyter|ms-|2022.9.1202862440
jupyter-keymap|ms-|1.0.0
jupyter-renderers|ms-|1.0.12
vscode-jupyter-cell-tags|ms-|0.1.6
vscode-jupyter-slideshow|ms-|0.1.5
remote-containers|ms-|0.262.3
remote-ssh|ms-|0.92.0
remote-ssh-edit|ms-|0.84.0
remote-wsl|ms-|0.72.0
cmake-tools|ms-|1.12.27
cpptools|ms-|1.12.4
cpptools-extension-pack|ms-|1.3.0
remote-explorer|ms-|0.0.2
debugger-for-chrome|msj|4.13.0
vetur|oct|0.36.1
indent-rainbow|ode|8.3.1
LiveServer|rit|5.7.9
mdx|sil|0.1.1
cmake|twx|0.0.17
highlight-matching-tag|vin|0.10.1
volar|Vue|1.0.9

(1 theme extensions excluded)

</details><details>
<summary>A/B Experiments</summary>

```
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
vscccc:30566498
pyindex848cf:30577861
nodejswelcome1cf:30587006
fc301958:30595537
282f8724:30602487
gswce1:30605430
3d0df643:30604793
dbltrim-noruby:30604474

```

</details>

<!-- generated by issue reporter -->