Lazarus

Using the Lazarus IDE => Editor => Topic started by: Muso on April 20, 2021, 03:20:59 am

Title: Unfolding bug after searching
Post by: Muso on April 20, 2021, 03:20:59 am
I noticed the following bug on unfolding a section:

- press Shit+Alt+0 to fold everything
- search for a procedure name
- try to unfold the found procedure

result: it is not unfolded but disappears, see the attached screencast.

Lazarus 2.1.0 r65025 FPC 3.2.0 x86_64-win64-win32/win64
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 04:29:28 am
Actually not a bug. But maybe an unexpected side effect of a feature.

Lets have a look.

1) Folding vs Hiding
- Folding means the first line stays visible
- Hiding ( lines with // comments at the start of line)
   Means the line gets hidden

Hidden lines have the unfold symbol on the line above (unfold is a down-arrow).
Also the "hide me" symbol is a "dot" not a "-"

2) You can hide any lines you want by selecting them.
The current selection automatically adds a "hide me" to the gutter.

3) When you search for the procedure name, it becomes selected.....

Well and as you can see in your image, the symbol at the start of that line changes.
And if you click it, the line gets hidden. The "unhide" symbol appears above.

So that is what happens...


The problem is that in any line there can be more than one actions (fold,hide,unfold).
And also more than one block to fold
Code: Pascal  [Select][+][-]
  1. if a then begin if b then begin
has 2 blocks opening. The gutter symbol gives access to the inner/last "begin" block.

Right click on the gutter (the thin part of the gutter with the fold symbols) will give you access to all the blocks.
Title: Re: Unfolding bug after searching
Post by: Muso on April 20, 2021, 10:56:12 am
Well and as you can see in your image, the symbol at the start of that line changes.

Thanks for the explanation.

As you can see in my screencast, all other procedures are folded and get the + button to unfold it. So why is the + button changed just because I found the procedure of interest by searching and not by just looking with my eyes?

I understand now that the feature is to provide hiding when a line is selected. But this should not be the case when selected by a search result.
I argue because the typical uses case is that you have tons of procedures and need to have the overview and to search/find the procedure of interest.

Therefore I would be happy if you could consider of adapting the hiding/folding feature a bit.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 02:52:15 pm
Btw, you can assign (if not set by default) shift-alt + do unfold (and Shift-Alt - to fold).
That will work, even if there is a selection.

provide hiding when a line is selected

When any part of a line is selected.

Quote
As you can see in my screencast, all other procedures are folded and get the + button to unfold it. So why is the + button changed just because I found the procedure of interest by searching and not by just looking with my eyes?
Because it is a selection. It does not matter by what action it come to be selected.

Quote
Therefore I would be happy if you could consider of adapting the hiding/folding feature a bit.

I do agree.

There should at least be an option to disable "hide selection" completely (we got options for all else).

It would also be good, if both (unfold and hide) could be displayed. I am not quite sure yet how.....
(This would not be in all cases witch more that one action, but probably only with opposing actions. expand and collapse)

You can add a feature request on our bugtracker.
I just don't know yet when I will be able to fit it in.

---
There is also  a bug, that somehow prevents the ability to configure the IDE to use shift mouse click to unfold, when the hide icon shows....
Though this config is only avail in the "advanced mouse actions". So it is all, but trivial.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 04:25:05 pm
Ok, so I did (partly) fix the advance mouse....

If you want to be able to "shift" or "shift-ctrl" click the "hide selected" icon, and yet have it unfold the line.

This only works, if you use any of the modifier keys (shift and/or ctrl). The editor is not smart enough to detect, if there are both actions. So you need to keep the default "fold" action, or you can't fold by mouse any more.


If you want to go that way.

Apply the patch (or edit the file) and recompile the IDE (the line numbers are trunk/2.1 ; but it should work for 2.0.x too)
https://github.com/User4martin/lazarus/commit/adfff37ad6509bc90c7a3dce4eb42d18b9bdbfb6
https://github.com/User4martin/lazarus/commit/adfff37ad6509bc90c7a3dce4eb42d18b9bdbfb6.diff

See the image on how to configure.
The below assumes you gonna use the shift + ctrl key.


1&2) You need to add an action, for what happens when you click on a "collapse" [ - ] or [ . ] symbol. (Because with the selection you well see the "hide" symbol)

3) There are already various actions.
- The image shows them *after* the change described here.
- To start with they will show a "-" in the shift column. That means those actions will trigger independent of the shift key (with or without shift)

As you gonna add an action that relies on "shift + left mouse", you need to tell all existing actions, that they should not trigger when shift is pressed. Otherwise they would conflict with the new action. (and you would get an error, trying to add the new action).

Note: You only need to look at actions with "up/down" = up. The "down" action, stays as it is.

For each of the existing "up" actions, you need to edit the action. You can do that by double click (or using the "change" button).
Then in the window that opens to edit the action (same window as in step 5, but having the settings for the existing action), clear the checkbox for "shift". That checkbox will be greyed to start with. "greyed" = does not matter. => change it to "unchecked".

4 & 5) Add a new action.
The image shows what settings the action needs.

The green line will be added, when you click ok.

---
After that you can shift+ctrl click the [ . ] symbol, and unfold the code.

You can also assign this to the middle mouse, without any shift. Then you do not need to edit the existing actions.
https://wiki.lazarus.freepascal.org/IDE_Window:_EditorMouseOptionsAdvanced
Title: Re: Unfolding bug after searching
Post by: Muso on April 20, 2021, 07:35:17 pm
Ok, so I did (partly) fix the advance mouse....

To be honest, I am an IDE beginner. I code with Pascal for years, but never had the time to dive into the IDE. Now I have a larger project and struggle with basic things. So maybe before you proceed, here is what I would find very useful:

- right-click on the + icon in front of a procedure/function and get in the context menu the option to un/fold all procedures/functions (like already implemented for comments)
- same as above but for all except blocks
- either a menu or a context menu option, to unfold everything to level 0
- the advanced mouse actions should be self-explanatory. because at the moment I don't understand what is e.g. the current shortcut to fold everything.

I updated Lazarus trunk via FCPupDeluxe and now I can no longer fold everything using Shit+Alt+0. So what do I have to use now for this?
I see in the Advanced Mouse options:

Fold Code   Left   Any   Up   -   -   Y   0      All (Nodes)

So I think I have to cleft-click while pressing the Ctrl button and then all nodes will be unfold. But this doesn't work
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 08:21:58 pm
Ok, so I did (partly) fix the advance mouse....
To be honest, I am an IDE beginner. I code with Pascal for years, but never had the time to dive into the IDE.

Actually I hadn't paid attention that you are using trunk, and that therefore you could just fpdeluxe up to the fixed version...

So you do not need to edit the file (or apply the patch).
If you did have to, it is easy.
- Open the file, edit the one line, as shown on the github page.
- Save the file
- Tools > Options > Build IDE
done.

But anyway, not needed.

Quote
So maybe before you proceed, here is what I would find very useful:

- right-click on the + icon in front of a procedure/function and get in the context menu the option to un/fold all procedures/functions (like already implemented for comments)
- same as above but for all except blocks
Nice ideas, but I have a large todo list, before this.

Quote
- either a menu or a context menu option, to unfold everything to level 0
"to level 0" is just a fancy way to say: unfold all / remove all folds?

If you have folded lines, then the fold gutter context menu has that entry.

Quote
- the advanced mouse actions should be self-explanatory. because at the moment I don't understand what is e.g. the current shortcut to fold everything.
The advanced mouse option, is a bit like Firefox "beware dragons" advanced options.

The normal mouse options, cover more than most people need. But there always had been a few people wanting something different. The advanced options are for this.
(Currently the overall options do not have a way have disabling advanced options, otherwise they would be invisible by default).

They are explained on the wiki. But they are to complex to be intuitive. (In a way they are a basic programming language)

In this case, I gave you the exact setting to apply. => that is to apply blindly, without understanding why. (the why is on the wiki)
 
Quote
I updated Lazarus trunk via FCPupDeluxe and now I can no longer fold everything using Shit+Alt+0. So what do I have to use now for this?
This should still work. Please check your keymap setting, as in the attached image.

Quote
I see in the Advanced Mouse options:

Fold Code   Left   Any   Up   -   -   Y   0      All (Nodes)

So I think I have to cleft-click while pressing the Ctrl button and then all nodes will be unfold. But this doesn't work
I assume that is in the section "collapsed". I.e. applies when you click on a [ + ] symbol

Depends on your reading of "all nodes".
"all nodes" here means: all nodes on this line.
Code: Pascal  [Select][+][-]
  1. if a then begin if b then begin
if both "begin" blocks are folded, you can either
- open one of them
- open both (all)

That does not apply to nodes on other lines.

If you want to, I can give you instructions, how to unfold all nodes on all lines, by clicking on the fold gutter.
(Ideally just clicking on the gutter outside of a [ +- ] symbol. I.e. empty parts of the fold gutter, or vertical line parts. / Or using middle button / Otherwise a lot more editing is needed).

Or send me your editoroptions.xml => and I add the middle click to unfold all, and send it back to you.



Title: Re: Unfolding bug after searching
Post by: Muso on April 20, 2021, 08:51:28 pm
Quote
- either a menu or a context menu option, to unfold everything to level 0
"to level 0" is just a fancy way to say: unfold all / remove all folds?

If you have folded lines, then the fold gutter context menu has that entry.

Yes, I meant to completely fold, like using Alt+Shift+1.
I don't see this in the context menu. I right-click onto the + icon in front of a procedure and get the attached.

So when I right-click onto the icon in front of a folded procedure I get a content option to unfold all, but when I right-click onto the icon in front of an unfolded procedure I get no context option to fold all.

Quote
They are explained on the wiki. But they are to complex to be intuitive. (In a way they are a basic programming language)
;D
Thanks for the info.

Quote
Quote
I updated Lazarus trunk via FCPupDeluxe and now I can no longer fold everything using Shit+Alt+0. So what do I have to use now for this?
This should still work. Please check your keymap setting, as in the attached image.

I run fpcupdeluxe another time to update trunk despite there are no new commits, and now it works again. Strange.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 09:06:25 pm
Quote
All (Nodes)
I changed the text for that to "All on line (Nodes)"

The "Nodes" part is, because this is used as the name in the dialog. Even though it is not of much meaning in the grid. (But for other options it is needed to be repeated)


Quote
- either a menu or a context menu option, to unfold everything to level 0
"to level 0" is just a fancy way to say: unfold all / remove all folds?

If you have folded lines, then the fold gutter context menu has that entry.

Yes, I meant to completely fold, like using Alt+Shift+1.
I don't see this in the context menu. I right-click onto the + icon in front of a procedure and get the attached.

So when I right-click onto the icon in front of a folded procedure I get a content option to unfold all, but when I right-click onto the icon in front of an unfolded procedure I get no context option to fold all.
It looks like you got the image when you clicked on a [ - ], not on a [ + ] ? Because the first line in the context menu has the [ - ] too.

You need to have at least one folded line in the file, in order to see the entry. If there is no folded line the entry is not in the menu (I.e there is no disabled entry, the entry is dropped entirely).

If you do have at least on fold, then you should get "unfold" all, anywhere you right click the fold part of the gutter.

Quote
I run fpcupdeluxe another time to update trunk despite there are no new commits, and now it works again. Strange.
Ends well, all's well.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 20, 2021, 09:13:48 pm
Btw, bit off topic, but useful for editing large code....

I used to do a lot of folding. Nowadays, I don't, I use a 2nd (or even 3rd) editor window.
Of course that depends on your monitor size.

The IDE can have the same unit open in 2 or 3 or more Windows. Each window scrolled to a diff location in the file. All windows are synchronized.

Look at the context menu of the editor tabs. "Clone to window"

Btw "Lock Page" will prevent the IDE from scrolling the view in that window, when you use code navigation. That is the IDE will rather switch to another window with that unit open, and only if no other option then it will scroll the locked view.
Useful, if you have the class declaration open in one window, and edit the implementation in the other window. Lock the window with the declaration.


Title: Re: Unfolding bug after searching
Post by: Muso on April 21, 2021, 07:33:59 pm
It looks like you got the image when you clicked on a [ - ], not on a [ + ] ?
You need to have at least one folded line in the file, in order to see the entry.

Yes, I click onto the [ - ] and need a context menu entry to FOLD everything. Instead I get the option to UNfold. But why UNfold an already unfolded section?
I mean when clicking on a [ + ] I get a context menu to UNfold, so why not also the other way round?

And as you can see in the attached screencast, I already have folded lines in the document.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 21, 2021, 08:05:41 pm
The "unfold all" relates to the entire file.
It is not specific to the current fold node. => If any where in the file there is any code  folded, then "unfold all" ("all" as in all lines in the file) will be shown.

A "fold all" does not exist. It only exists via the keyboard.

The word "all" is problematic, since there is
- all in the flie
- all on the line


If you want to take a look
Code: Text  [Select][+][-]
  1. \ide\sourcesyneditor.pas  
  2. class  TIDESynGutterCodeFolding (and the base class in synedit).
Code: Pascal  [Select][+][-]
  1. TIDESynGutterCodeFolding.CreatePopUpMenuEntries
adds some of the entries.

You can see the callbacks, like to fold comments
Code: Pascal  [Select][+][-]
  1. then AddPopUpItem(synfFoldCommentsInSelection).OnClick := @PopClickedFoldComment

Where you can see how it walks the lines of the unit, and makes the folds....

---
Or Search for  "ecFoldLevel1" to see how to fold all. (Or send it to Synedits.CommandProcessor)


Title: Re: Unfolding bug after searching
Post by: Muso on April 21, 2021, 10:40:00 pm
A "fold all" does not exist. It only exists via the keyboard.

And this is what I want. Just an option (not necessarily in the context menu) that offers the same functionality like Alt+Shift+1.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 22, 2021, 12:56:15 am
Well, IMHO (but I accept it is for you) a plain "fold all" is not to appealing, because depending on fold settings, it could fold entire "interface" and "implementation" sections. (They can be folded, if enabled).
Or it could fold global level type/var blocks => almost the same as "interface".

A "fold all ..." where ... is in the list of procedures, classes, ..., even except. That I can see appealing.
But having them all in the menu at the same time, would be to much.
So some selection logic would have to apply. (Enable via options, nested sub menu, match elements on current line...)
In any case, at current, I have a big amount of other TODO. So I wont work on them myself.


The closest you can get with the current IDE is using the advanced mouse option.
They can map almost any key-stroke command to a mouse click.
So you could use middle mouse on the fold gutter, or maybe even double left click.

On my earlier image:
Step 2 would be "Fold tree"
Step 3 skipped
Step 5
- set to middle click / you can try double click
- Action: Ide Command
- Once the action is set, a very long list will be in the 2nd dropdown, and it will contain "fold to level 1" (unfortunately they are not ordered....)



Title: Re: Unfolding bug after searching
Post by: Muso on April 22, 2021, 02:54:24 am
A "fold all ..." where ... is in the list of procedures, classes, ..., even except. That I can see appealing.

This is what I already proposed in https://forum.lazarus.freepascal.org/index.php/topic,54240.msg402913.html#msg402913

- right-click on the + icon in front of a procedure/function and get in the context menu the option to un/fold all procedures/functions (like already implemented for comments)
- same as above but for all except blocks

Quote
But having them all in the menu at the same time, would be to much.

Why the same time? The idea is to click on the [ +/- ] icon of e.g. an except block and then get the context menu to un/fold all except blocks.

Concerning the fold all feature I only don't understand why there is a shortcut for this but no menu entry. I had to google around if and how this is possible and I think it would be nice when users can find this on their own in one of the menu.

However, I don't insist on anything, just making proposal. I am a happy user of Laz 2.1 and hope to get a final release of it soon. I am an OpenSource developer too in another project (Qt/C++, however) and know that the spare time is limited.
This way thanks for all you great work. I mean I reported the last days several issues and all have already been fixed. This is really amazing!
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 22, 2021, 03:26:25 am
Why the same time? The idea is to click on the [ +/- ] icon of e.g. an except block and then get the context menu to un/fold all except blocks.
+1

Quote
Concerning the fold all feature I only don't understand why there is a shortcut for this but no menu entry. I had to google around if and how this is possible and I think it would be nice when users can find this on their own in one of the menu.
<slight sarcasm on>
Well, good question. Unfortunately I do not remember why. It is 12 Years 9 Month and 11 days since it was added. :) :)

Based on https://bugs.freepascal.org/view.php?id=12561
https://github.com/User4martin/lazarus/commit/94c21c4c3ebbb024386ac9946ac5dc21d136f8c4
https://github.com/User4martin/lazarus/commit/7d80cf42dfbb5dd9658d32076c6bc7703eb24343
<slight sarcasm off>

Back then the fold gutter did not have a context menu, nor was there a concept of different context menus depending on where you clicked in the editor.
As for the main menu, I don't recall, maybe I was to lazy, maybe it did not occur to me, or I thought it would be overkill.

I agree its not easy to find. But if I would add it now, I would go with something along your idea. "all procedures" instead of "level x".
The "level x" always had the issue that to fold procedures you need "level n" (depending on your settings), but then in the interface type section, that had to match "class" level, so You need to enable/disable the correct options. Maybe the correct settings are default now, don't know. I haven't used this in a while.

Yes, I guess the only way to find them are searching the keymap... Maybe the wiki could do with a page showcasing all the fold features.

And, oh wait... There is a recent new Package: IdeScout. Which allows you do search for features. Install, open, and search for "fold".

Quote
However, I don't insist on anything, just making proposal. I am a happy user of Laz 2.1 and hope to get a final release of it soon. I am an OpenSource developer too in another project (Qt/C++ however) and know that the spare time is limited.
This way thanks for all you great work. I mean I reported the last days several issues and all have al ready been fixed. This is really amazing!

As I said, you can make a feature request.
Though it wont make to much of a difference, if and when I find the time to work on folding again, I might add something anyway... But there are other fish to fry...

Btw, I'm absolutely happy to hear your ideas (and that the feature is useful to you, always nice to know).

Anyway, you've seen I posted where to find the code. So maybe some one finds this, and wants to pick it up.
Title: Re: Unfolding bug after searching
Post by: Muso on April 22, 2021, 04:27:41 pm
I agree its not easy to find. But if I would add it now, I would go with something along your idea. "all procedures" instead of "level x".

+1

Quote
And, oh wait... There is a recent new Package: IdeScout. Which allows you do search for features. Install, open, and search for "fold".

I cannot find it in the online package manager. I found it however, in the list of available but not installed packages.
Now I cannot find docs on how to use the package. How can I set now the fold properties?
Title: Re: Unfolding bug after searching
Post by: Martin_fr on April 22, 2021, 04:43:31 pm
IdeScout: The package is not fold specific. Its an "help me find a feature". (Sorry did not want to get your hopes up)

It has one key shortcut ( I have it on alt-shift-p / but I may have changed it from the original)
It opens a window, with a search field, and it shows you relevant IDE functions, of which you can select one to act.

So it's key board driven. It does not solve your quest for a mouse driven option. But it can help find the keyboard combo for those commands, as they show up in the list.


Of course for now, it just moves the issue of finding functions. You have to find IDE scout first.

Maybe someone has an animated paper clip icon, and it can be added to some toolbar...
Title: Re: Unfolding bug after searching
Post by: Muso on April 22, 2021, 04:53:19 pm
It has one key shortcut ( I have it on alt-shift-p / but I may have changed it from the original)

Oh, oh! Why do you (meaning the developer community) hide all these cool features? Lazarus should by default have this search feature.
So can you (meaning the developer who is responsible) please integrate this package fully into Laz in the way that
- it is by default installed
- it appears as menu Tools -> "Find feature within Lazarus"

Then every user can just use this menu item to quickly find the different features. Especially IDE newbies like me need this and as a newbie you would never come to the idea that you first need to install a package, finding out what package and then that it can only be accessed using a shortcut.
Searching a program's feature is quite essential and very helpful.
Title: Re: Unfolding bug after searching
Post by: Martin_fr on May 07, 2021, 01:02:57 pm
Just a note, I mailed it to the team. No takers so far.
I still don't have the time myself either.

Best to add a feature request on Mantis.
Title: Re: Unfolding bug after searching
Post by: Muso on May 10, 2021, 10:59:00 pm
Best to add a feature request on Mantis.

Thanks. I created now this issue in Mantis:
https://bugs.freepascal.org/view.php?id=38873
TinyPortal © 2005-2018