Recent

Author Topic: Search-Replace Dialog: "Don't Close" Option?  (Read 210 times)

del

  • Jr. Member
  • **
  • Posts: 68
Search-Replace Dialog: "Don't Close" Option?
« on: October 06, 2019, 06:21:53 pm »
I have a block of selected text. There are several different words I want to change. But each time I make a change, the dialog closes and the block of selected text becomes un-selected. So I have to repeat the process for each different word. Is there - or could there be - an option to keep alive the selection and the dialog until you finally close the dialog when you're done?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #1 on: October 06, 2019, 06:35:03 pm »
Not easily no...  Of course in theory one could implement anything.

1) If the dialog is open, it blocks you from editing.
Of course that could be changed.

2) If you edit, you loose the selection. You could even make a new selection (for copy and paste). In fact you loose it already because the found term becomes selected.
Of course (if implemented) the search replace could remember the original bounds of the selection. And adjust them if there are text changes.
The editor could even get an 2ndary block highlight for this remembered selection.



I do not know your exact workflow, but there may be other options.

What you describe sounds like a case for syncro edit. https://wiki.lazarus.freepascal.org/New_IDE_features_since#Syncron-Edit

Select the text, and activate syncro-edit. Any word with more than one occurrence in the selection (for really huge selection only the first n words) will be in a selectable cell (tab key).
Edit each such word, and all other occurrences of it (within that block) will change too.

However it only works for full words.

del

  • Jr. Member
  • **
  • Posts: 68
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #2 on: October 06, 2019, 06:52:12 pm »
1) If the dialog is open, it blocks you from editing.
You continue to edit (replace) in the dialog, the selected text stays selected beneath the dialog. So for example there are three variables in a selected block that you want to change:

red_dogs -> redDogs
DietCoke -> dietCoke
loudmusic -> loudMusic

You could make all these changes right from the dialog, one after the other, then close the dialog. VS lets you do this, as does IIRC notpad++ and / or geany. Or maybe even nedit (defunct - not supported). You would have a little check box to click that would keep the dialog open until you were done.

(edit - I know Pascal doesn't care about my last two examples, in those cases it would just be for visual consistency)
« Last Edit: October 06, 2019, 06:56:17 pm by del »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #3 on: October 06, 2019, 07:24:11 pm »
Despite I still think you may want to try syncro....

If I get that right, this is if you do:
a) replace all
  => Otherwise you return to the editor and there is on say what happens to the selection
b) without confirmation
  => Because "confirmation" selects the individual item, and the original selection is gone.

But anyway, all you need is a checkbox: "Restore selection afterwards".
That would even mean that "b" is not needed, you could have confirm dialogs.

The replace dialog could close, if the selection is back, you can open it again.


Afaik code that tracks the orig selection already exists. So it would only be to restore it. the bounds (after replaces) should already be known
« Last Edit: October 06, 2019, 07:26:05 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #4 on: October 06, 2019, 07:33:30 pm »
If you want to look at it ("restore selection"):

The dialog is called from ide/sourceEditor.pp
  TSourceEditor.StartFindAndReplace(Replace:boolean);

The dialog is in unit ide/FindReplaceDialog
  (keep visual change to minimum)

The Search is in
components/synedit/synedit
  TCustomSynEdit.SearchReplaceEx

In synedit the selection is traced in local vars: ptStart, ptEnd
Add a flag to AOption, and restore selection at the end.

del

  • Jr. Member
  • **
  • Posts: 68
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #5 on: October 06, 2019, 07:37:30 pm »
Despite I still think you may want to try syncro....
Whoa! Sorry - I like that. That is slick! I misunderstood your post. I like the "live action" effect. Thanks! File this one under "Solved".
 :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #6 on: October 06, 2019, 07:53:20 pm »
Despite I still think you may want to try syncro....
Whoa! Sorry - I like that. That is slick! I misunderstood your post. I like the "live action" effect. Thanks! File this one under "Solved".
 :)

Glad it helped.

The IDE has a lot of tricks, so many that even long time users get sometimes surprised.

Some more really recommended reading (This one is a MUST READ):
https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools

Also you can record macros for the editor, or even write them in PascalScript (that allows for many missing features to be added on the fly):
https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros
https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript

And you can use multi-caret:
https://wiki.lazarus.freepascal.org/New_IDE_features_since#Multi_Caret

I also recommend to install the package "Cody" (The identifier dictionary is truly heaven sent)
https://wiki.lazarus.freepascal.org/Cody

del

  • Jr. Member
  • **
  • Posts: 68
Re: Search-Replace Dialog: "Don't Close" Option?
« Reply #7 on: October 06, 2019, 08:20:34 pm »
Awesome - that Syncro edit really does the trick. I'll install Cody and start playing around with it. Thanks again!