]> git.lizzy.rs Git - micro.git/commitdiff
a few miscellaneous fixes and improvements (#1105)
authorJT Olio <hello@jtolio.com>
Sun, 13 May 2018 01:31:57 +0000 (19:31 -0600)
committerZachary Yedidia <zyedidia@gmail.com>
Sun, 13 May 2018 01:31:57 +0000 (21:31 -0400)
* 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

  <space><space>line1
  <space><space>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
cmd/micro/bindings.go
cmd/micro/cellview.go
cmd/micro/view.go
runtime/help/keybindings.md

index a291c88d53e75c9f284f863b77c4bdc0f39505d6..83eec1440d82768b809879d8db588f46a847c3e9 100644 (file)
@@ -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) {
index d8a0ede0d067ced7f11b0950e11aefffc6e93a37..e3a02841718f97ab6cfd497607c1ea85436146c5 100644 (file)
@@ -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,
index 52fe73ff30142dc1b034a8531b8f21d6c00663f1..b0cb6523c3602312b9ba8470d7cae65e83e12ed6 100644 (file)
@@ -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)
                                }
                        }
index 724d2bac2d549f35b9ecbfbe492e07ca623e3046..d6d9470f2dac66d2f4b91cd230125857cdec6155 100644 (file)
@@ -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()
index 922b5b7ecf3217a6e68b30d032a99896a67377d4..eee3e2fad31757b9314effa8780f6a5f05569879 100644 (file)
@@ -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