-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Description of the problem or steps to reproduce
- Open any file that have many lines
- Select several lines (not with mouse it looks like it messes start and end of the selection)
- Press down
Expected behavior
Cursor is moved to the end. To the line next to end of selection but at least to the last line of selection.
Actual behavior
Even if you selected 1000 lines pressing down will move cursor to the second line of selection.
NOTE: Pressing up works correctly and moves cursor up
How it was found and what problem it brought
I needed to select whole lines in custom sidebar on moving up and down. Something like the thing you can see in filemanager plugin. And the following example works while you run micro with disabled softwrap. But when you enable softwrap (and make sure that line you currently selected is softwrapped) pressing down will move cursor to the next "visual" line but it will be the same "actual" line. When you are on the second "visual" line of text the "SelectLine()" will select whole "actual" line. Pressing down will move it to the second "visual" line and now we are in a loop...
Minimal reproducible example, just copy it as plugin to your plugin dir to
function onCursorDown(buffer_pane)
buffer_pane:SelectLine()
end
function onCursorUp(buffer_pane)
buffer_pane:SelectLine()
end
Mouse inconsistency
Like mentioned in #3055 if you select something with mouse the direction from what you selected text matters. If you selected text from up to bottom, everything works as with keyboard selection but. But if you select line from bottom to up the things will swap: pressing up will result in moving cursor to the one line up before last line and pressing down will work correctly and normally.
About filemanager and workaround
I tried to overcome the bug and found the workaround the same is in filemanager plugin. The pressing up is done via onCursorUp hook because pressing up works good but pressing down is handled in different way. It is done via preCursorDown that handles cursor down movement before it happens and manually moves cursor down and then return false from hook to let micro know that the action was handled and micro mustn't perform it....
Possible root of the problem
UpNfunction that is also used for down don't respectCurrentSelectionand just use itself like it is simple 1 char cursor
- I am not sure how important it is but see Inconsistent cursor up/down moving after selecting with keyboard/mouse #3055 (comment)
Specifications
Commit hash: 68d88b5
OS: Debian12
Terminal: foot