From 81e1a6e1573e6f51a84dccefcfef3a76d8338d32 Mon Sep 17 00:00:00 2001 From: Camille Scholtz Date: Fri, 20 May 2016 00:04:53 +0200 Subject: [PATCH 1/2] Give shortcuts more message feedback, add duplicate line option (fixes #124) --- cmd/micro/bindings.go | 35 ++++++++++++++++++++++++++++------- runtime/help/help.md | 4 ++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index e1077d57..ec86043c 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -52,6 +52,7 @@ func InitBindings() { "Copy": (*View).Copy, "Cut": (*View).Cut, "CutLine": (*View).CutLine, + "DuplicateLine": (*View).DuplicateLine, "Paste": (*View).Paste, "SelectAll": (*View).SelectAll, "OpenFile": (*View).OpenFile, @@ -278,17 +279,19 @@ func DefaultBindings() map[string]string { "CtrlC": "Copy", "CtrlX": "Cut", "CtrlK": "CutLine", + "CtrlD": "DuplicateLine", "CtrlV": "Paste", "CtrlA": "SelectAll", "Home": "Start", "End": "End", "PgUp": "PageUp", "PgDn": "PageDown", - "CtrlU": "HalfPageUp", - "CtrlD": "HalfPageDown", - "CtrlR": "ToggleRuler", - "CtrlL": "JumpLine", - "Delete": "Delete", + // Find alternative key + // "CtrlU": "HalfPageUp", + // "CtrlD": "HalfPageDown", + "CtrlR": "ToggleRuler", + "CtrlL": "JumpLine", + "Delete": "Delete", } } @@ -654,12 +657,14 @@ func (v *View) FindPrevious() bool { // Undo undoes the last action func (v *View) Undo() bool { v.eh.Undo() + messenger.Message("Undid action") return true } // Redo redoes the last action func (v *View) Redo() bool { v.eh.Redo() + messenger.Message("Redid action") return true } @@ -668,7 +673,7 @@ func (v *View) Copy() bool { if v.Cursor.HasSelection() { clipboard.WriteAll(v.Cursor.GetSelection()) v.freshClip = true - messenger.Message("Copied selection to clipboard") + messenger.Message("Copied selection") } return true } @@ -677,7 +682,6 @@ func (v *View) Copy() bool { func (v *View) CutLine() bool { v.Cursor.SelectLine() if v.freshClip == true { - if v.Cursor.HasSelection() { if clip, err := clipboard.ReadAll(); err != nil { messenger.Error(err) @@ -692,6 +696,7 @@ func (v *View) CutLine() bool { v.lastCutTime = time.Now() v.Cursor.DeleteSelection() v.Cursor.ResetSelection() + messenger.Message("Cut line") return true } @@ -702,10 +707,23 @@ func (v *View) Cut() bool { v.Cursor.DeleteSelection() v.Cursor.ResetSelection() v.freshClip = true + messenger.Message("Cut selection") } return true } +// Duplicate the current line +func (v *View) DuplicateLine() bool { + v.Cursor.SelectLine() + line := v.Cursor.GetSelection() + v.Cursor.SetLoc(v.Cursor.curSelection[1]) + v.eh.Insert(v.Cursor.Loc(), line) + v.Cursor.End() + v.Cursor.ResetSelection() + messenger.Message("Duplicated line") + return true +} + // Paste whatever is in the system clipboard into the buffer // Delete and paste if the user has a selection func (v *View) Paste() bool { @@ -717,6 +735,7 @@ func (v *View) Paste() bool { v.eh.Insert(v.Cursor.Loc(), clip) v.Cursor.SetLoc(v.Cursor.Loc() + Count(clip)) v.freshClip = false + messenger.Message("Pasted clipboard") return true } @@ -813,8 +832,10 @@ func (v *View) HalfPageDown() bool { func (v *View) ToggleRuler() bool { if settings["ruler"] == false { settings["ruler"] = true + messenger.Message("Enabled ruler") } else { settings["ruler"] = false + messenger.Message("Disabled ruler") } return false } diff --git a/runtime/help/help.md b/runtime/help/help.md index 853a00e2..341213fd 100644 --- a/runtime/help/help.md +++ b/runtime/help/help.md @@ -41,9 +41,8 @@ These are the default keybindings, along with their actions. * Ctrl-c: Copy * Ctrl-x: Cut * Ctrl-k: Cut line +* Ctrl-d: Duplicate line * Ctrl-v: Paste -* Ctrl-u: Half page up -* Ctrl-d: Half page down * PageUp: Page up * PageDown: Page down * Home: Go to beginning of line @@ -108,6 +107,7 @@ Here are the defaults: "CtrlC": "Copy", "CtrlX": "Cut", "CtrlK": "CutLine", + "CtrlD": "DuplicateLine" "CtrlV": "Paste", "CtrlA": "SelectAll", "Home": "Start", From 2d99d0d57a6e9ada886d334847637908f4bfcd44 Mon Sep 17 00:00:00 2001 From: Camille Scholtz Date: Fri, 20 May 2016 00:06:09 +0200 Subject: [PATCH 2/2] Forgot a comma there --- runtime/help/help.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/help/help.md b/runtime/help/help.md index 341213fd..5b4986b2 100644 --- a/runtime/help/help.md +++ b/runtime/help/help.md @@ -107,7 +107,7 @@ Here are the defaults: "CtrlC": "Copy", "CtrlX": "Cut", "CtrlK": "CutLine", - "CtrlD": "DuplicateLine" + "CtrlD": "DuplicateLine", "CtrlV": "Paste", "CtrlA": "SelectAll", "Home": "Start",