Recent

Author Topic: Folding and column mode selection/editing  (Read 679 times)

Чебурашка

  • Hero Member
  • *****
  • Posts: 569
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Folding and column mode selection/editing
« on: December 15, 2022, 09:09:17 am »
Hello
I do a huge column mode operations when I code (please don't blame me or say don't do like that :) ).

I saw a unexpected behaviour of lazarus (on deb 11.5 with laz 2.0.10, maybe newer versions are ok?).

To reproduce:

1. Let be the following code (picture 001):

Code: Pascal  [Select][+][-]
  1. procedure Procedure01();
  2. begin
  3.   // body of the procedure 01 -- 0 1 2 3 4 5 6 7 8 9
  4. end;
  5. procedure Procedure02();
  6. begin
  7.   // body of the procedure 02 -- 0 1 2 3 4 5 6 7 8 9
  8. end;
  9.  

2. Now fold to the procedure signature (picture 002);
3. Then make vertical selection before "()" in the two folded lines with the procedures (picture 003);
4. Press space one or more times (in my example below you can see I pressed 4 times) (picture 004)
5. Unfold the code (picture 005)

Code: Pascal  [Select][+][-]
  1. procedure Procedure01    ();
  2. begin                    
  3.   // body of the proc    edure 01 -- 0 1 2 3 4 5 6 7 8 9
  4. end;                    
  5. procedure Procedure02    ();
  6. begin
  7.   // body of the procedure 02 -- 0 1 2 3 4 5 6 7 8 9
  8. end;
  9.  

The body of the Procedure01 is messed up, as apparently the editing occurs like if folding was not active.

Other editors (Microsoft VS is an example) edit only the visible part instead, that is how things should work IMO.
« Last Edit: December 15, 2022, 12:51:59 pm by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9868
  • Debugger - SynEdit - and more
    • wiki
Re: Folding and column mode selection/editing
« Reply #1 on: December 15, 2022, 02:07:45 pm »
Ah, yes....

In that case the (vertical line of) carets follow the selection.
And the selection is continuous.

1) If you fold code and make a normal selection (covering the fold) it will include the invisible (folded away) part of the code.
IMHO that is ok.
This allows to copy/cut entire procedures (while only seeing the header) and paste (move) them elsewhere.

2) If you fold code and make a column mode selection, it will select the columns in all lines of the text (visible or not).
That follows the above concept.
I can see that this may not necessarily be expected....
Both (include the folded lines in the selection, or excluding them) could be considered correct.

3) The setting of carets follows (2)

I have seen to few use cases, to judge whether this is the better choice....
I do agree there is a usecase for editing only the non-folded lines.


I can see that it's not for your usecase.

The desired behaviour would have to be added as a new feature. Probably with an option to toggle it.



Workarounds:
Depending on how many lines you need to set carets on...

* Use  ctrl - shift - left mouse button.
This adds an extra caret. So you can set a caret each line.

* Use ctrl - shift - Insert followed by cursor down
  ctrl - shift - Insert  will add a caret at the current location
  cursor down will move down (skipping folded lines)
And repeat those 2 steps.

You can record those 2 keystrokes as a macro, and assign them to a new key combo.
Then you have exactly what you need: Add a caret at current location, and move the original caret one visible line down.
https://wiki.freepascal.org/IDE_Window:_Editor_Macros

The Marco will look like this
Code: Text  [Select][+][-]
  1. begin
  2. ecPluginMultiCaretSetCaret;
  3. ecDown;
  4. end.


https://wiki.lazarus.freepascal.org/SynEdit_MultiCaret_plugin
The carets added in the above ways will not "cancel on move" (cursor up/down/left/right). They will "follow moves". So you need to press esc to get rid of the multi carets.
This can be changed in Tools > Options > Editor > General


Чебурашка

  • Hero Member
  • *****
  • Posts: 569
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Folding and column mode selection/editing
« Reply #2 on: December 15, 2022, 02:16:29 pm »
In that case the (vertical line of) carets follow the selection.
And the selection is continuous.

[...]

The desired behaviour would have to be added as a new feature. Probably with an option to toggle it.

Thanks, hope this observation becomes helpful in future.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018