micro icon indicating copy to clipboard operation
micro copied to clipboard

Improve and unify `CopyLine`, `CutLine`, `DeleteLine`, `DuplicateLine` actions

Open dmaluka opened this issue 1 year ago • 1 comments

  • Clean up and unify behavior of the actions: Copy and Cut copy or cut only the selection (and return false if there is no selection), while CopyLine and CutLine copy or cut the current line.
  • Add new Duplicate action which duplicates the selection only, and similarly clean up the actions behavior: Duplicate duplicates the selection (and returns false if there is no selection), while DuplicateLine duplicates the current line. See #3110
  • Correspondingly, update and unify the default keybindings:

current ones:

"Ctrl-c":         "CopyLine|Copy",
"Ctrl-x":         "Cut",
"Ctrl-d":         "DuplicateLine",

changed to:

"Ctrl-c":         "Copy|CopyLine",
"Ctrl-x":         "Cut|CutLine",
"Ctrl-d":         "Duplicate|DuplicateLine",

so the default behavior of these keys doesn't change.

  • Make CopyLine, CutLine, DeleteLine and DuplicateLine respect the selection (see #3328). When there is a multi-line selection, these actions should not just copy/cut/delete/duplicate the "current" line, as usual. This behavior is at least confusing, since when there is a selection, the cursor is not displayed, so the user doesn't know which line is the current one.

    So change the behavior of these actions: copy/cut/delete/duplicate all lines covered by the selection, not just the current line. Note that we cut/delete/copy/duplicate not just the selection itself (for that we have other actions: Copy, Cut etc) but whole lines, i.e. if the first and/or the last line of the selection is only partially within the selection, we cut/delete/copy the entire first and last lines nonetheless.

  • Various bugfixes and improvements.

Fixes #3328 Fixes #3110

dmaluka avatar Jun 09 '24 14:06 dmaluka

Hi

I have had some thoughts about duplicate see https://github.com/zyedidia/micro/issues/3110. Mainly about leaving cursor position/selection unchanged - so we can repeat duplications as many times as necessary.

Kind Regards Gavin Holt

Gavin-Holt avatar Jun 16 '24 22:06 Gavin-Holt

@JoeKar last time we agreed not to merge this before 2.0.14, to avoid changing keybindings semantics right before the release. Now that 2.0.14 has happened, shall we merge it?

And #3403 too (once we finish its review)?

dmaluka avatar Sep 15 '24 13:09 dmaluka

I think there is a bug introduced in fdacb289624a5b6568571cc443e60b201ef5212f. The last line is selected only when CopyLine, CutLine or DeleteLine is done with no selection on the line even if it is not empty. I tried looking if I can fix it and I think BufPane.selectLines only will have to be changed when fixing it, but I do not know about the code structure and style much so I cannot easily come up with a good way to fix it.

niten94 avatar Oct 24 '24 05:10 niten94

Thanks, fixed in #3519.

dmaluka avatar Oct 24 '24 06:10 dmaluka