Reselect Last Selection lazarus / 9-Editor ---------------------------------------------------------------------- sfeinst · 2025-07-02 00:03 I tried looking thru shortcuts and I might be missing it - or it doesn't exist.  I'm looking for a way to reselect the last selection in the editor.  Basically, if you've used Vim, the equivalent to gv. I find if I perform a replace in a selection, the replace completes and the text is no longer selected.  But there are many times I want to perform multiple replaces and I have to reselect the text again. ---------------------------------------------------------------------- Martin_fr · 2025-07-02 00:08 There indeed isn't currently such an option. Interesting idea though. In the meantime, depending on what you replace, have you tried syncro edit? https://wiki.lazarus.freepascal.org/New_IDE_features_since#Syncron- Edit ---------------------------------------------------------------------- 440bx · 2025-07-02 01:47 Quote from: sfeinst on July 02, 2025, 02:03:05 amI find if I perform a replace in a selection, the replace completes and the text is no longer selected.  But there are many times I want to perform multiple replaces and I have to reselect the text again. Maybe setting "Selection" to "Persistent block" in the Editor options might be a solution for you. ---------------------------------------------------------------------- Thaddy · 2025-07-02 10:49 A undo buffer for ctrl-shift-e? ---------------------------------------------------------------------- Martin_fr · 2025-07-02 10:58 Ideally "replace" or at least "replace in selection" should not remove the selection. But, as it selects the first found instance when asking if it should replace, that does not work. For that to work a 2ndary selection would be needed. Undo (normal undo) wont work either, even if it stored changes to selection => because the undo would first undo the replace. When "replace" finds something, it FIRST removes/changes the selection, THEN changes the text. And undo goes in reverse order. ---------------------------------------------------------------------- sfeinst · 2025-07-02 12:34 Quote from: 440bx on July 02, 2025, 03:47:22 amMaybe setting "Selection" to "Persistent block" in the Editor options might be a solution for you. After doing the Replace All, selection still lost, but thanks for the suggestion. BTW, I didn't state it in the original post, but I usually use Replace All in Selection.  I don't think that changes any answers, just mentioning it. ---------------------------------------------------------------------- 440bx · 2025-07-02 13:07 Quote from: sfeinst on July 02, 2025, 02:34:30 pmAfter doing the Replace All, selection still lost, but thanks for the suggestion. You're welcome.  I thought it was worth a shot.  Unfortunately it didn't work but, it didn't take much time to try it either. ---------------------------------------------------------------------- Martin_fr · 2025-07-02 15:04 There isn't a solution at the moment. Well, you can probably write Pascal-script macros that set a bookmark at the start and end of the selection. And then another that sets the selection from those bookmarks. You need to spare 2 bookmarks though. And get into the Pascal script macros. ---------------------------------------------------------------------- 440bx · 2025-07-02 17:06 Quote from: Martin_fr on July 02, 2025, 05:04:21 pmWell, you can probably write Pascal-script macros that set a bookmark at the start and end of the selection. And then another that sets the selection from those bookmarks. You need to spare 2 bookmarks though. And get into the Pascal script macros. That's an interesting idea. Do you think that instead of using bookmarks, it might be sufficient to record the line numbers of the start and end of the selection ? The only concern that comes to mind is if the text-replace operation modifies the original selection's number of lines but, I think that's a bit of a rare case ... is this a correct impression ? ---------------------------------------------------------------------- Thaddy · 2025-07-02 17:09 Well, yes, correct. Store the diffs. ---------------------------------------------------------------------- 440bx · 2025-07-02 17:21 Never mind. I just remembered there is no way to pass data between macros, because of that the use of bookmarks is pretty much forced.  ETA: Actually, just thought of a hack that would allow sharing data between macros.  That would remove the need to use bookmarks.  I haven't tried it yet, so don't really know if it will work.  Something to do, hopefully sometime soon. ---------------------------------------------------------------------- 440bx · 2025-07-09 21:59 I thought it would be fun to solve this problem using a macro... here is the macro: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  BeginPt    : TPOINT;  EndPt      : TPOINT;   BeginCaret : TPOINT; begin  with BeginPt do  begin    x := 0;    y := 0;  end;   with EndPt do  begin    x := 0;    y := 0;  end;   with BeginCaret do  begin    x := BeginPt.x;    y := BeginPt.y;  end;    if Caller.SelAvail then  begin    BeginPt := Caller.BlockBegin;    EndPt := Caller.BlockEnd;     with BeginCaret do    begin      x := BeginPt.x;      y := BeginPt.y;    end;     //ShowMessage('BeginPt.x: ' + IntToStr(BeginPt.x) + '  ' +    //            'BeginPt.y: ' + IntToStr(BeginPt.y) + '  ' +    //            'EndPt.x: '   + IntToStr(EndPt.x)   + '  ' +    //            'EndPt.y: '   + IntToStr(EndPt.y));  end;   ecReplace;     // do the search and replace   if BeginPt.x <> 0 then  begin    Caller.BlockBegin := BeginPt;    Caller.BlockEnd   := EndPt;     Caller.CaretXY    := BeginCaret;  end;end.                                It's written in such a way that if nothing is selected the macro's action are the same as the actions done by the original replace command. if there is text selected then, it does the replacement with the addition that the text _stays_ selected ready for a next replace operation to be done on it.  That way, it is not even necessary to re- select the text since it stays selected. Two possible ways of using the macro are: 1. re-assign the current key combination assigned to the "replace" command to this macro (default is ctrl-r) if going that route, do it in two steps, first delete the key assigned to "replace" then assign it to the macro.  This because, if it's not deleted first, the key re- assignment eventually gets lost.  This way effectively replaces the current action with this macro's action. 2. assign any unused key combination to this macro.  This way, there are two ways of performing a replace operation, the original one and this new one that keeps the text selected ready for another replace operation. HTH. ETA: Just for the record, the variable BeginCaret isn't really needed.  BeginPt has the same information. ---------------------------------------------------------------------- sfeinst · 2025-07-10 01:26 I tried it out - after researching how to support macros  It would perfectly - minimal testing but nice. Took me longer to find a good unused key combination than it did to actually save the macro Thanks ---------------------------------------------------------------------- 440bx · 2025-07-10 02:09 You're welcome.