Recent

Author Topic: Feature request/suggestion  (Read 786 times)

440bx

  • Hero Member
  • *****
  • Posts: 6088
Feature request/suggestion
« on: January 09, 2026, 02:44:37 am »
Hello,

When searching for a string in the editor and the string is found, it is somewhat often the case that the string found is at the bottom of the visible window which is often inconvenient as it does not make visible any additional information/context related to the search string.

For instance, consider the two attached screenshots.

In the first screenshot, the string "type" was found at the bottom of the window and because it is at the bottom, useful information about the type is not visible.

In the second screenshot, the string "type" is located towards the top of the window, thereby making information related to the "string" visible.

That's the request/suggestion: put the found string near the top of the window in order for what is below the found string to be visible.  Ideally, the number of lines where the found string is displayed from the top of the window would be configurable.

Comments welcome.

ETA:

Got to give it a little more thought but, something tells me it might be possible to implement this feature using a macro.
« Last Edit: January 09, 2026, 03:24:38 am by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12116
  • Debugger - SynEdit - and more
    • wiki
Re: Feature request/suggestion
« Reply #1 on: January 09, 2026, 09:54:34 am »
Actually, I don't think that "on top" would suit me. IMHO in the lower third is a good range... That said currently it may sometimes be too low. Only sometimes though.

E.g. when searching next, and just staying within the current procedure, then minimum amount of scrolling is very good and that means as close to the lower border as possible.

So this should be an option.

440bx

  • Hero Member
  • *****
  • Posts: 6088
Re: Feature request/suggestion
« Reply #2 on: January 09, 2026, 10:17:39 am »
So this should be an option.
An option would be fine.

I'll give some more thought about implementing that using a macro.  If it can be done with a macro then there would be no need to add any code anywhere in Lazarus to implement it, which would make this request moot but, I haven't worked on making it a macro yet (because of that, I don't really know if it can be done that way.)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12116
  • Debugger - SynEdit - and more
    • wiki
Re: Feature request/suggestion
« Reply #3 on: January 09, 2026, 10:46:20 am »
Macros don't have any functions to scroll the editor. Well move the caret, but then you need to move it back. Which requires a bookmark. A simple page down, page up will loose position, if it hits the end of the file.


440bx

  • Hero Member
  • *****
  • Posts: 6088
Re: Feature request/suggestion
« Reply #4 on: January 09, 2026, 11:40:44 am »
Macros don't have any functions to scroll the editor. Well move the caret, but then you need to move it back. Which requires a bookmark. A simple page down, page up will loose position, if it hits the end of the file.
I agree...

I'm still hoping that I'll think of some way to do it... it doesn't look good at this time but, I'm not ready to throw the towel yet ;)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

DomingoGP

  • Full Member
  • ***
  • Posts: 113
Re: Feature request/suggestion
« Reply #5 on: January 09, 2026, 03:37:57 pm »

Perhaps this macro can serve as inspiration for you to create a macro that does what you need.

It centers the current line on the tenth line of the editor, but does not maintain the selection.

It's just a proof of concept, it needs some tweaking. If the cursor is past the last line of the viewport, it doesn't work properly, and it doesn't maintain the current selection either.

Code: Pascal  [Select][+][-]
  1. // center current line in editor.
  2. var
  3.   caret: TPoint;
  4.   topLine,linesToScroll,i: integer;
  5. const
  6.   DESIRED_WINDOW_LINE = 10;
  7. begin
  8.   caret := Caller.CaretXY;
  9.   ecPageTop;               // find window top line.
  10.   topLine:= Caller.CaretY;
  11.   Caller.CaretXY := caret; // restore caret position.
  12.   linesToScroll := (caret.Y - DESIRED_WINDOW_LINE) - topLine;
  13.   if linesToScroll > 0 then
  14.   begin
  15.     for i := 1 to linesToScroll do
  16.       ecScrollDown;
  17.   end
  18.   else if linesToScroll < 0 then
  19.   begin
  20.     for i := 1 to -linesToScroll do
  21.       ecScrollUp;
  22.   end;
  23. end.
  24.  

440bx

  • Hero Member
  • *****
  • Posts: 6088
Re: Feature request/suggestion
« Reply #6 on: January 09, 2026, 06:07:18 pm »
Thank you Domingo.  That was definitely helpful.

Here is the completed macro for anyone who might be interested (for Find Again, the one for Find is the same except for using ecFind instead of ecFindAgain, comments that reference ecFindAgain should be edited to reflect the change.)
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. { Purpose: this macro places the found string DESIRED_WINDOW_LINE from the    }
  4. {          top of the edit window.  It works with the Find again option.      }
  5. {                                                                             }
  6. {          a macro that works with the first find is basically the same       }
  7. {          except that instead of using ecFindAgain it uses ecFind            }
  8.  
  9.  
  10. procedure Halt();
  11.   { halts macro execution                                                     }
  12.   { note that it causes an error to be output in the Messages window which    }
  13.   { ideally wouldn't happen (since the objective is just to stop the macro)   }
  14.  
  15. var
  16.   i : integer;
  17.  
  18. begin
  19.   i := i div 0;
  20. end;
  21.  
  22.  
  23. var
  24.   BeginCaret    : TPOINT;
  25.  
  26.   TopLine       : integer;
  27.   BottomLine    : integer;
  28.  
  29.   LinesToScroll : integer;
  30.  
  31.   SelBeginPt    : TPOINT;
  32.   SelEndPt      : TPOINT;
  33.  
  34.   Lines         : integer;
  35.  
  36.   i             : integer;
  37.  
  38. const
  39.   DESIRED_WINDOW_LINE = 10;
  40.  
  41. begin
  42.   ecFindAgain;    { repeat the find                                           }
  43.  
  44.   with SelBeginPt do
  45.   begin
  46.     { prophylactic initialization                                             }
  47.  
  48.     X := 0;
  49.     Y := 0;
  50.   end;
  51.  
  52.   if not Caller.SelAvail then
  53.   begin
  54.     { if FindAgain did not find anything then stop the macro                  }
  55.  
  56.     Halt();
  57.   end;
  58.  
  59.   { FindAgain found something, save what it selected                          }
  60.  
  61.   SelBeginPt := Caller.BlockBegin;
  62.   SelEndPt   := Caller.BlockEnd;
  63.  
  64.   BeginCaret := Caller.CaretXY;   { save the caret location                   }
  65.  
  66.   { we need to know the value of the Top line, Bottom line and how many lines }
  67.   { there are                                                                 }
  68.  
  69.   ecPageTop;
  70.   TopLine := Caller.CaretY;          { Top line                               }
  71.  
  72.   ecPageBottom;
  73.   BottomLine := Caller.CaretY;       { Bottom line                            }
  74.  
  75.   Lines      := Caller.LinesCount;   { Total lines                            }
  76.  
  77.   { figure out if some scrolling is needed and can be done                    }
  78.  
  79.   if BottomLine >= Lines then
  80.   begin
  81.     { we are at the end of the file, scrolling would not reveal anything but  }
  82.     { blank lines.  Therefore we are done.                                    }
  83.  
  84.     Halt();
  85.   end;
  86.  
  87.   LinesToScroll := (SelBeginPt.Y - DESIRED_WINDOW_LINE) - TopLine;
  88.   if LinesToScroll + SelBeginPt.Y > Lines then
  89.   begin
  90.     { ensure we don't scroll so much that we reveal blank space that occurs   }
  91.     { after the end of file                                                   }
  92.  
  93.     LinesToScroll := Lines - SelBeginPt.Y;
  94.   end;
  95.  
  96.   for i := 1 to LinesToScroll do
  97.   begin
  98.     ecScrollDown;
  99.   end;
  100.  
  101.   { re-establish the selection and the caret's location                       }
  102.  
  103.   if SelBeginPt.x <> 0 then
  104.   begin
  105.     Caller.BlockBegin := SelBeginPt;
  106.     Caller.BlockEnd   := SelEndPt;
  107.  
  108.     Caller.CaretXY    := BeginCaret;
  109.   end;
  110. end.
  111.  
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

n7800

  • Hero Member
  • *****
  • Posts: 607
  • Lazarus IDE contributor
    • GitLab profile
Re: Feature request/suggestion
« Reply #7 on: January 09, 2026, 11:24:36 pm »
That's the request/suggestion: put the found string near the top of the window in order for what is below the found string to be visible.  Ideally, the number of lines where the found string is displayed from the top of the window would be configurable.

By the way, CodeTools has similar options for this behavior (see attachment).

Theoretically, search could use them too (despite the fact that they're located in the "CodeTools" category).

440bx

  • Hero Member
  • *****
  • Posts: 6088
Re: Feature request/suggestion
« Reply #8 on: January 09, 2026, 11:45:17 pm »
Thank you @n7800, I'm currently using the macro I wrote since it does exactly what I want but, I'll try with the settings you pointed out.

Thanks again.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018