Recent

Author Topic: Block/Line Indent\Unindent Hotkey with persistent selection  (Read 1775 times)

Tony Stone

  • Full Member
  • ***
  • Posts: 219
Block/Line Indent\Unindent Hotkey with persistent selection
« on: February 10, 2023, 01:42:09 am »
What is the expected behavior when using the shortcuts to indent/un-indent a line (CTRL+I / U) when there is a persistent selection.  I just discovered the persistent block today and it looks very handy however it seems there may, or may not be a bug in it.  When I have a block persistently selected and i move the caret to another line, what should be indented or un-indented when hotkeys are pressed?  It seems it saw at different times the persistent selection indented and other times the line with the caret indented.  So I am not sure how that would work in other editors but something seems off to me.  I am also wondering if it would make more sense to have a persistent block by using a key modifier while selecting text rather than having a option in the Options > General > Persistent Block section?  It seems like an option you would not often want on but when you want to use it you want it quickly enabled.  Just some thoughts and curious if I should consider a bug report.


Update:
I may have posted about this to soon.  I don't think I was accurate when I saw the line with a caret indented while there was a persistent selection.  Just not sure now.  I am experimenting with it now and I think it is probably working as designed.  I am still curious though if there is a way I can use a key modifier while selecting text to force it to be a persistent selection?  Going through options now trying to figure that one out still.
« Last Edit: February 10, 2023, 01:47:16 am by Tony Stone »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #1 on: February 10, 2023, 03:25:57 am »
Selection disappears when you move caret without modifier. When you have selection you can of course use CTRL/SHIFT+Arrow keys to scroll / edit selection.

But there's one more feature. Source Editor supports multiple carets and a new caret can be added by Ctrl+Click*. In that case you can have persistant selection and more carets.

*) I'm not sure if CTRL+Click is default or if I configured it.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #2 on: February 10, 2023, 10:29:37 am »
@Baazen: persistent selection => this is an option, allowing the selection to be independent of the caret.

@Tony:

There probably isn't any expected behaviour. I don't think (meaning I am pretty sure) that any thought was ever spend on how it should behave. The indent functionality was simple implemented and tested with normal selection. And the behaviour for persistent is the same, never mind if sensible.
This is probably true for a lot of functions.

I don't use persistent block myself, so I am happy to receive feedback on it.
If I was asked, I would say that maybe it should either:
- act only on the selection if the caret is in the selection (or at one of the bounds of it)
- act only on the selection if the caret is on any line that is (at least partly) covered by the selection (even if the caret is not in the selection).
  The excludes lines, where the selection bound is at the start-of-line (the previous line is selected including the linefeed // that means the selection bound is at a line, which has no selection highlight)

EDIT:
Needs also separate testing for block indent with
- tab key
- ctrl-i
« Last Edit: February 10, 2023, 10:33:23 am by Martin_fr »

Tony Stone

  • Full Member
  • ***
  • Posts: 219
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #3 on: February 10, 2023, 02:15:29 pm »
I have researched it a little more last night.  It is not a new feature it doesn't seem.  Probably does need a little refinement from what I was able to do with it.  Like I said it would be very handy if it worked the way I was expecting which would be like the following:

Only set a persistent selection with a key modifier, while using the mouse or SHIFT+Arraow Keys(that could be cumbersome and too many keys)

And I would expect a CTRL-C copy to copy the selected text and CTRL-V paste at the carret.  It seemed to me that more than once a paste replaced the selection which didnt seem right.

Either way for the most part I am not so sure this is a feature very many people would use but last night while trying to clean up some of my code it seemed like it was gonna be an awesome tool to use while moving text etc.  Just didn't seem to work out quite right.  I will have to tinker with it some more over the weekend... chances are I am probably not using it right.  I also found some references to using CTRL-K and CTRL-B to persistently select blocks but again... i think I was possibly doing it wrong.  I will see what better feedback I can give this weekend on it's use.  I am also wondering if having a cloned code editor played a role in some of the incosistent behavior.  I will experiment with out a cloned editor as well.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #4 on: February 10, 2023, 03:31:21 pm »
Only set a persistent selection with a key modifier, while using the mouse or SHIFT+Arraow Keys(that could be cumbersome and too many keys)
That would be a new feature.

Currently "persistent selection" is an option that is either on or off (and also has no key to toggle it / which would be enough to kind of make your request work)

You may have seen "sticky" selection. But that just means you don't have to hold shift to expand the selection ((should) work independent of persistent).
That allows you to set a bookmark, search for some text, start sticky selecting at that "some text", go to the bookmark, and finish selecting. (great in editor-macros)

Quote
And I would expect a CTRL-C copy to copy the selected text and CTRL-V paste at the carret.  It seemed to me that more than once a paste replaced the selection which didnt seem right.
That should be the case for any mode, except

When you have none-persistent selection, then the caret must be at the selection. In this case the option "overwrite selection" will decide if the pasted text replaces the existing selection or not.
That option also affects, what happens to a non-persistent selection when you type new text.

Quote
Either way for the most part I am not so sure this is a feature very many people would use but last night while trying to clean up some of my code it seemed like it was gonna be an awesome tool to use while moving text etc.  Just didn't seem to work out quite right.  I will have to tinker with it some more over the weekend... chances are I am probably not using it right.  I also found some references to using CTRL-K and CTRL-B to persistently select blocks but again... i think I was possibly doing it wrong.  I will see what better feedback I can give this weekend on it's use.

There is ctrl-k, b and ctrl-k, k to  set begin/end of the selection. IIRC only works when the option "persistent selection" is on.
It does not force a persistent selection, when that option is off (though that may be an interesting idea)

ctrl-k, b to move the persistent block...

There are also thinks like (independent of persistent / not for column selection)
- move line(s) up/down
- move selection up/down (and iirc left/right)
- copy, but append to existing clipboard
- copy current line / copy line, append

Quote
I am also wondering if having a cloned code editor played a role in some of the incosistent behavior.  I will experiment with out a cloned editor as well.
Should not matter at all.
None of those commands have any reference to the code dealing with cloned-edits.

Tony Stone

  • Full Member
  • ***
  • Posts: 219
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #5 on: February 11, 2023, 03:46:52 am »
Real quick thoughts.  While I haven't had time to mess with it much tonight here is what some of my expected behavior would be:

I would expect that I could set a persistent selection using a key modifier when selecting text.  Then be able to move the caret and type anywhere etc.  But I would expect that I should still be able to make a new text selection(and the persistent one would be temporarily deselected) then do what i want with that selection, when there is no more selected text the persistent selection comes back.


I think that is more or less what I was expecting.


But on a somewhat related note... I WOULD LOVE to see the issue fixed where if I am selecting text with my mouse, and a hint pops up under my mouse cursor, I dont want the selection to stop selecting text.  It is like the text selection stops as if the mouse button was released.  I think because the editor loses focus due to the code hint.  (I know that explanation was hard to follow and I am not sure if it is a bug or not)



Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #6 on: February 11, 2023, 04:25:05 am »
Quote
But on a somewhat related note... I WOULD LOVE to see the issue fixed where if I am selecting text with my mouse, and a hint pops up under my mouse cursor, I dont want the selection to stop selecting text.  It is like the text selection stops as if the mouse button was released.  I think because the editor loses focus due to the code hint.  (I know that explanation was hard to follow and I am not sure if it is a bug or not)

What OS and widgetset? I never had this issue on Linux+Qt.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Tony Stone

  • Full Member
  • ***
  • Posts: 219
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #7 on: February 11, 2023, 05:44:49 am »
I am running on Linux Mint.  GTK widgetset.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #8 on: February 11, 2023, 09:58:56 am »
But on a somewhat related note... I WOULD LOVE to see the issue fixed where if I am selecting text with my mouse, and a hint pops up under my mouse cursor, I dont want the selection to stop selecting text.  It is like the text selection stops as if the mouse button was released.  I think because the editor loses focus due to the code hint.  (I know that explanation was hard to follow and I am not sure if it is a bug or not)

That should be reported as a bug. On windows you can continue selecting...

IMHO there are 2 issues.

1) The Hint should not disturb the ongoing action.

2) Maybe there should not be a hint to start with. (No Hints while the mouse button is down?) Not sure....

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9857
  • Debugger - SynEdit - and more
    • wiki
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #9 on: February 11, 2023, 10:23:11 am »
I would expect that I could set a persistent selection using a key modifier when selecting text.

Generally that is a valid idea.

I wouldn't use a modifier key, because we are running out of them. And if you look at the amount of keymap entries that are selection related (select-up/down/left/rigth/word/word-end|begin.... And again for column mode...) => far too many.

But I could imagine any of the following (including several or all of them)
- ctrl-k, b   to always make a persistent selection (Note, you can assign what ever key you like)
- Having a key that you can press once you made a selection: "make the current selection persistent"
- (maybe?) Having a key that you can press immediately before you make a selection (expires on any non-selecting action)
- Having a key to toggle the global option (or 2 keys, for on/off each)

The 3rd one doesn't appeal to much to me....

Please feel free to file a feature request on the issue tracker.

Quote
Then be able to move the caret and type anywhere etc.  But I would expect that I should still be able to make a new text selection(and the persistent one would be temporarily deselected) then do what i want with that selection, when there is no more selected text the persistent selection comes back.

There is only one selection.
So a persistent selection will not come back after another selection had been made....

Also I personally would not feel that this is intuitive.  But even if I would read "persistent" as surviving a temp-selection, then I would expect it to be visible all the time. And just ctrl-c to act on the last made selection....
But anyway, I don't think that is going to happen...

I could imagine a bookmark inspired feature, but rather than name bookmarks using a stack. And then on that stack store the current caret-pos, and current (if existing) selection. So then you can do
- save(push) caret/selection
- do work (if need saved x/y will be amended)
- pop

Though not directly implemented as a new command. Rather extend PascalScript Editor Macros. Provide them with a persistent storage that allows each macro to store values between invocation (and share with other macros).
Then a macro as the above could be implemented...

Tony Stone

  • Full Member
  • ***
  • Posts: 219
Re: Block/Line Indent\Unindent Hotkey with persistent selection
« Reply #10 on: February 11, 2023, 10:33:23 pm »
I will submit a bug report on the hint stealing focus issue.  I might even try to fix it with your suggestion(that will probably go bad haha) but it has been annoying me for a very long time and I am suprised no one else has this issue or submitted a bug report.  I also do like the idea of using a key to make a selection persistent.  That seems to be the simplest usage of such a feature.  I like the idea of toggling the global option with a key as well.  Unfortunately I am not the one to try and implement that and probably not the ideal person to get input from on this.  It seems it was a desired feature by someone at one point and they probably had a way better idea of how it should work.  Either way I will get that bug report done and maybe attempt a solution myself.  If I am succesful i'll post what I did here.

Thanks!

 

TinyPortal © 2005-2018