Author Topic: v20 - Search and Replace Issue  (Read 1437 times)

Tim Kemp

  • Senior Community Member
  • Posts: 536
  • Hero Points: 90
v20 - Search and Replace Issue
« on: September 22, 2015, 02:46:22 pm »
This is something I've asked about before. I see it's still not fixed in v20.

When you perform a search and replace within a selection, if the shape of the text changes as a result of a replacement, subsequent replacements act on text that now fits inside the selection, not the text that originally fit in the selection.

A case that I often run into is transforming a line into a column. For example:
Code: [Select]
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10to
Code: [Select]
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10

It seems like a simple replacement, but if you select the line of numbers and do a search and replace to transform it, only the first one will change and you will be left with:
Code: [Select]
0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10

I've run into the opposite case too, where the text contracts as a result of the replacements, and text which originally wasn't in the selection, gets pulled in and changed.

I usually end up copying the selected text into an empty buffer, doing the replacement and then copying it back. It sure would be nice if something like that happened automatically.

This seems so basic, I can't believe I'm the only person affected.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4964
  • Hero Points: 409
Re: v20 - Search and Replace Issue
« Reply #1 on: September 22, 2015, 03:13:08 pm »
Possible work around: Use Shift and arrow keys to make the selection and select 0 characters on the line below. This way when the line is split the end of the selection is moved down so you keep get matches within the selection.

It would be nice if this case was handled though.

Tim Kemp

  • Senior Community Member
  • Posts: 536
  • Hero Points: 90
Re: v20 - Search and Replace Issue
« Reply #2 on: September 22, 2015, 03:53:51 pm »
Your solution works great for entire lines being selected. It doesn't seem to work for block selections though.

I started with:
Code: [Select]
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Selected a block that contained the "3, 4, 5," on each line. I used the arrow keys to do that. Then I did a search and replace on ", " to replace it with "". Instead of:
Code: [Select]
0, 1, 2, 345, 6, 7, 8, 9, 10
0, 1, 2, 345, 6, 7, 8, 9, 10
0, 1, 2, 345, 6, 7, 8, 9, 10

I ended up with:
Code: [Select]
0, 1, 2, 3456789, 10
0, 1, 2, 3456789, 10
0, 1, 2, 3456789, 10

Is there a work around for this too?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4964
  • Hero Points: 409
Re: v20 - Search and Replace Issue
« Reply #3 on: September 22, 2015, 05:29:01 pm »
Block/column selections don't get adjusted. No work around. There are even more complex problems with proportional fonts and column selections which are now supported by v20.

Try doing the search and replace in reverse. I think that might be a better work around for the first problem too.

Tim Kemp

  • Senior Community Member
  • Posts: 536
  • Hero Points: 90
Re: v20 - Search and Replace Issue
« Reply #4 on: September 22, 2015, 06:11:26 pm »
I assume you mean, search backwards. That does seem like a better work around. Thanks.

mwb1100

  • Senior Community Member
  • Posts: 143
  • Hero Points: 13
Re: v20 - Search and Replace Issue
« Reply #5 on: September 22, 2015, 11:49:46 pm »
Block/column selections don't get adjusted. No work around. There are even more complex problems with proportional fonts and column selections which are now supported by v20.

It seems that Tim's algorithm:

Quote
I usually end up copying the selected text into an empty buffer, doing the replacement and then copying it back. It sure would be nice if something like that happened automatically.

might solve that problem, too.  It's probably more than a simple bug-fix, but maybe you guys can schedule some rework at some point on search-and-replace in a selection (even if for v21) to operate this way behind the scenes.