actions: CutLineAppend added (#3477)

It was confusing for people that CutLine will occasionally accumulate cut lines if executed multiple times before the clipboard's content is pasted. Shortcut Ctrl-k is reserved for CutLineAppend, since CutLine already has Ctrl-x binded as well.
This commit is contained in:
MarkZaytsev 2024-12-20 15:07:13 +07:00
parent 2898f1590d
commit b18e190daf
5 changed files with 38 additions and 9 deletions

View File

@ -1394,11 +1394,37 @@ func (h *BufPane) Cut() bool {
// CutLine cuts the current line to the clipboard. If there is a selection,
// CutLine cuts all the lines that are (fully or partially) in the selection.
// CutLine will replace the clipboard's current buffer.
func (h *BufPane) CutLine() bool {
totalLines := h.selectLines()
if totalLines == 0 {
return false
}
h.Cursor.CopySelection(clipboard.ClipboardReg)
h.freshClip = true
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
if totalLines > 1 {
InfoBar.Message(fmt.Sprintf("Cut %d lines", totalLines))
} else {
InfoBar.Message("Cut line")
}
h.Relocate()
return true
}
// CutLineAppend cuts the current line to the clipboard. If there is a selection,
// CutLineAppend cuts all the lines that are (fully or partially) in the selection.
// CutLineAppend will append the selection to the clipboard's buffer.
func (h *BufPane) CutLineAppend() bool {
nlines := h.selectLines()
if nlines == 0 {
return false
}
totalLines := nlines
if h.freshClip {
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
@ -1411,15 +1437,17 @@ func (h *BufPane) CutLine() bool {
} else {
h.Cursor.CopySelection(clipboard.ClipboardReg)
}
h.freshClip = true
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
if totalLines > 1 {
InfoBar.Message(fmt.Sprintf("Cut %d lines", totalLines))
if nlines > 1 {
InfoBar.Message(fmt.Sprintf("Cut %d lines. Total lines in buffer: %d.", nlines, totalLines))
} else {
InfoBar.Message("Cut line")
InfoBar.Message(fmt.Sprintf("Cut line. Total lines in buffer: %d.", totalLines))
}
h.Relocate()
return true
}

View File

@ -788,6 +788,7 @@ var BufKeyActions = map[string]BufKeyAction{
"CopyLine": (*BufPane).CopyLine,
"Cut": (*BufPane).Cut,
"CutLine": (*BufPane).CutLine,
"CutLineAppend": (*BufPane).CutLineAppend,
"Duplicate": (*BufPane).Duplicate,
"DuplicateLine": (*BufPane).DuplicateLine,
"DeleteLine": (*BufPane).DeleteLine,

View File

@ -47,7 +47,7 @@ var bufdefaults = map[string]string{
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-d": "Duplicate|DuplicateLine",
"Ctrl-v": "Paste",
"Ctrl-a": "SelectAll",
@ -148,7 +148,7 @@ var infodefaults = map[string]string{
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-v": "Paste",
"Home": "StartOfTextToggle",
"End": "EndOfLine",

View File

@ -50,7 +50,7 @@ var bufdefaults = map[string]string{
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-d": "Duplicate|DuplicateLine",
"Ctrl-v": "Paste",
"Ctrl-a": "SelectAll",
@ -151,7 +151,7 @@ var infodefaults = map[string]string{
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-v": "Paste",
"Home": "StartOfTextToggle",
"End": "EndOfLine",

View File

@ -513,7 +513,7 @@ conventions for text editing defaults.
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-d": "Duplicate|DuplicateLine",
"Ctrl-v": "Paste",
"Ctrl-a": "SelectAll",
@ -639,7 +639,7 @@ are given below:
"Ctrl-y": "Redo",
"Ctrl-c": "Copy|CopyLine",
"Ctrl-x": "Cut|CutLine",
"Ctrl-k": "CutLine",
"Ctrl-k": "CutLineAppend",
"Ctrl-v": "Paste",
"Home": "StartOfTextToggle",
"End": "EndOfLine",