mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 07:15:34 -04:00
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:
parent
2898f1590d
commit
b18e190daf
@ -1394,11 +1394,37 @@ func (h *BufPane) Cut() bool {
|
|||||||
|
|
||||||
// CutLine cuts the current line to the clipboard. If there is a selection,
|
// 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 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 {
|
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()
|
nlines := h.selectLines()
|
||||||
if nlines == 0 {
|
if nlines == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
totalLines := nlines
|
totalLines := nlines
|
||||||
if h.freshClip {
|
if h.freshClip {
|
||||||
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
|
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
|
||||||
@ -1411,15 +1437,17 @@ func (h *BufPane) CutLine() bool {
|
|||||||
} else {
|
} else {
|
||||||
h.Cursor.CopySelection(clipboard.ClipboardReg)
|
h.Cursor.CopySelection(clipboard.ClipboardReg)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.freshClip = true
|
h.freshClip = true
|
||||||
h.Cursor.DeleteSelection()
|
h.Cursor.DeleteSelection()
|
||||||
h.Cursor.ResetSelection()
|
h.Cursor.ResetSelection()
|
||||||
h.Cursor.StoreVisualX()
|
h.Cursor.StoreVisualX()
|
||||||
if totalLines > 1 {
|
if nlines > 1 {
|
||||||
InfoBar.Message(fmt.Sprintf("Cut %d lines", totalLines))
|
InfoBar.Message(fmt.Sprintf("Cut %d lines. Total lines in buffer: %d.", nlines, totalLines))
|
||||||
} else {
|
} else {
|
||||||
InfoBar.Message("Cut line")
|
InfoBar.Message(fmt.Sprintf("Cut line. Total lines in buffer: %d.", totalLines))
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -788,6 +788,7 @@ var BufKeyActions = map[string]BufKeyAction{
|
|||||||
"CopyLine": (*BufPane).CopyLine,
|
"CopyLine": (*BufPane).CopyLine,
|
||||||
"Cut": (*BufPane).Cut,
|
"Cut": (*BufPane).Cut,
|
||||||
"CutLine": (*BufPane).CutLine,
|
"CutLine": (*BufPane).CutLine,
|
||||||
|
"CutLineAppend": (*BufPane).CutLineAppend,
|
||||||
"Duplicate": (*BufPane).Duplicate,
|
"Duplicate": (*BufPane).Duplicate,
|
||||||
"DuplicateLine": (*BufPane).DuplicateLine,
|
"DuplicateLine": (*BufPane).DuplicateLine,
|
||||||
"DeleteLine": (*BufPane).DeleteLine,
|
"DeleteLine": (*BufPane).DeleteLine,
|
||||||
|
@ -47,7 +47,7 @@ var bufdefaults = map[string]string{
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-d": "Duplicate|DuplicateLine",
|
"Ctrl-d": "Duplicate|DuplicateLine",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Ctrl-a": "SelectAll",
|
"Ctrl-a": "SelectAll",
|
||||||
@ -148,7 +148,7 @@ var infodefaults = map[string]string{
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Home": "StartOfTextToggle",
|
"Home": "StartOfTextToggle",
|
||||||
"End": "EndOfLine",
|
"End": "EndOfLine",
|
||||||
|
@ -50,7 +50,7 @@ var bufdefaults = map[string]string{
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-d": "Duplicate|DuplicateLine",
|
"Ctrl-d": "Duplicate|DuplicateLine",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Ctrl-a": "SelectAll",
|
"Ctrl-a": "SelectAll",
|
||||||
@ -151,7 +151,7 @@ var infodefaults = map[string]string{
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Home": "StartOfTextToggle",
|
"Home": "StartOfTextToggle",
|
||||||
"End": "EndOfLine",
|
"End": "EndOfLine",
|
||||||
|
@ -513,7 +513,7 @@ conventions for text editing defaults.
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-d": "Duplicate|DuplicateLine",
|
"Ctrl-d": "Duplicate|DuplicateLine",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Ctrl-a": "SelectAll",
|
"Ctrl-a": "SelectAll",
|
||||||
@ -639,7 +639,7 @@ are given below:
|
|||||||
"Ctrl-y": "Redo",
|
"Ctrl-y": "Redo",
|
||||||
"Ctrl-c": "Copy|CopyLine",
|
"Ctrl-c": "Copy|CopyLine",
|
||||||
"Ctrl-x": "Cut|CutLine",
|
"Ctrl-x": "Cut|CutLine",
|
||||||
"Ctrl-k": "CutLine",
|
"Ctrl-k": "CutLineAppend",
|
||||||
"Ctrl-v": "Paste",
|
"Ctrl-v": "Paste",
|
||||||
"Home": "StartOfTextToggle",
|
"Home": "StartOfTextToggle",
|
||||||
"End": "EndOfLine",
|
"End": "EndOfLine",
|
||||||
|
Loading…
Reference in New Issue
Block a user