From ae9bb763fb0083ca856d0579a4d5b1532dd1fc90 Mon Sep 17 00:00:00 2001 From: JT Olio Date: Sat, 12 May 2018 19:31:57 -0600 Subject: [PATCH] a few miscellaneous fixes and improvements (#1105) * add binding for more primitive backspace * support selecting page up and page down * fix matchbraceleft for braces that start on x=0 * fix multiline copy-paste indenting let's say you have two lines like line1 line2 so you start from cursor x=0 and select both lines, then paste. we don't want any leading whitespace in this case, because the cursor is already at x=0 and the selection already includes whitespace. --- cmd/micro/actions.go | 36 ++++++++++++++++++++++++++++++++++++ cmd/micro/bindings.go | 3 +++ cmd/micro/cellview.go | 2 +- cmd/micro/view.go | 5 ++++- runtime/help/keybindings.md | 3 +++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index a291c88d..83eec144 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -1515,6 +1515,42 @@ func (v *View) PageDown(usePlugin bool) bool { return false } +// SelectPageUp selects up one page +func (v *View) SelectPageUp(usePlugin bool) bool { + if usePlugin && !PreActionCall("SelectPageUp", v) { + return false + } + + if !v.Cursor.HasSelection() { + v.Cursor.OrigSelection[0] = v.Cursor.Loc + } + v.Cursor.UpN(v.Height) + v.Cursor.SelectTo(v.Cursor.Loc) + + if usePlugin { + return PostActionCall("SelectPageUp", v) + } + return true +} + +// SelectPageDown selects down one page +func (v *View) SelectPageDown(usePlugin bool) bool { + if usePlugin && !PreActionCall("SelectPageDown", v) { + return false + } + + if !v.Cursor.HasSelection() { + v.Cursor.OrigSelection[0] = v.Cursor.Loc + } + v.Cursor.DownN(v.Height) + v.Cursor.SelectTo(v.Cursor.Loc) + + if usePlugin { + return PostActionCall("SelectPageDown", v) + } + return true +} + // CursorPageUp places the cursor a page up func (v *View) CursorPageUp(usePlugin bool) bool { if usePlugin && !PreActionCall("CursorPageUp", v) { diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index d8a0ede0..e3a02841 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -80,6 +80,8 @@ var bindingActions = map[string]func(*View, bool) bool{ "End": (*View).End, "PageUp": (*View).PageUp, "PageDown": (*View).PageDown, + "SelectPageUp": (*View).SelectPageUp, + "SelectPageDown": (*View).SelectPageDown, "HalfPageUp": (*View).HalfPageUp, "HalfPageDown": (*View).HalfPageDown, "StartOfLine": (*View).StartOfLine, @@ -255,6 +257,7 @@ var bindingKeys = map[string]tcell.Key{ "Escape": tcell.KeyEscape, "Enter": tcell.KeyEnter, "Backspace": tcell.KeyBackspace2, + "OldBackspace": tcell.KeyBackspace, // I renamed these keys to PageUp and PageDown but I don't want to break someone's keybindings "PgUp": tcell.KeyPgUp, diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index 52fe73ff..b0cb6523 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -76,8 +76,8 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { curX := buf.Cursor.X curLoc := buf.Cursor.Loc if buf.Settings["matchbraceleft"].(bool) { - curX-- if curX > 0 { + curX-- curLoc = curLoc.Move(-1, buf) } } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 724d2bac..d6d9470f 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -198,7 +198,10 @@ func (v *View) ToggleTabbar() { } func (v *View) paste(clip string) { - leadingWS := GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y)) + leadingWS := "" + if v.Cursor.X > 0 { + leadingWS = GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y)) + } if v.Cursor.HasSelection() { v.Cursor.DeleteSelection() diff --git a/runtime/help/keybindings.md b/runtime/help/keybindings.md index 922b5b7e..eee3e2fa 100644 --- a/runtime/help/keybindings.md +++ b/runtime/help/keybindings.md @@ -187,6 +187,8 @@ Start End PageUp PageDown +SelectPageUp +SelectPageDown HalfPageUp HalfPageDown StartOfLine @@ -352,6 +354,7 @@ CtrlRightSq CtrlCarat CtrlUnderscore Backspace +OldBackspace Tab Esc Escape