diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index 34c4c672..4bc282ba 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/gdamore/tcell" "github.com/mitchellh/go-homedir" "github.com/zyedidia/clipboard" + "github.com/zyedidia/tcell" ) var bindings map[tcell.Key]func(*View) bool @@ -21,36 +21,42 @@ func InitBindings() { bindings = make(map[tcell.Key]func(*View) bool) actions := map[string]func(*View) bool{ - "CursorUp": (*View).CursorUp, - "CursorDown": (*View).CursorDown, - "CursorLeft": (*View).CursorLeft, - "CursorRight": (*View).CursorRight, - "InsertEnter": (*View).InsertEnter, - "InsertSpace": (*View).InsertSpace, - "Backspace": (*View).Backspace, - "Delete": (*View).Delete, - "InsertTab": (*View).InsertTab, - "Save": (*View).Save, - "Find": (*View).Find, - "FindNext": (*View).FindNext, - "FindPrevious": (*View).FindPrevious, - "Undo": (*View).Undo, - "Redo": (*View).Redo, - "Copy": (*View).Copy, - "Cut": (*View).Cut, - "CutLine": (*View).CutLine, - "Paste": (*View).Paste, - "SelectAll": (*View).SelectAll, - "OpenFile": (*View).OpenFile, - "Beginning": (*View).Beginning, - "End": (*View).End, - "PageUp": (*View).PageUp, - "PageDown": (*View).PageDown, - "HalfPageUp": (*View).HalfPageUp, - "HalfPageDown": (*View).HalfPageDown, - "StartOfLine": (*View).StartOfLine, - "EndOfLine": (*View).EndOfLine, - "ToggleRuler": (*View).ToggleRuler, + "CursorUp": (*View).CursorUp, + "CursorDown": (*View).CursorDown, + "CursorLeft": (*View).CursorLeft, + "CursorRight": (*View).CursorRight, + "SelectLeft": (*View).SelectLeft, + "SelectRight": (*View).SelectRight, + "WordRight": (*View).WordRight, + "WordLeft": (*View).WordLeft, + "SelectWordRight": (*View).SelectWordRight, + "SelectWordLeft": (*View).SelectWordLeft, + "InsertEnter": (*View).InsertEnter, + "InsertSpace": (*View).InsertSpace, + "Backspace": (*View).Backspace, + "Delete": (*View).Delete, + "InsertTab": (*View).InsertTab, + "Save": (*View).Save, + "Find": (*View).Find, + "FindNext": (*View).FindNext, + "FindPrevious": (*View).FindPrevious, + "Undo": (*View).Undo, + "Redo": (*View).Redo, + "Copy": (*View).Copy, + "Cut": (*View).Cut, + "CutLine": (*View).CutLine, + "Paste": (*View).Paste, + "SelectAll": (*View).SelectAll, + "OpenFile": (*View).OpenFile, + "Beginning": (*View).Beginning, + "End": (*View).End, + "PageUp": (*View).PageUp, + "PageDown": (*View).PageDown, + "HalfPageUp": (*View).HalfPageUp, + "HalfPageDown": (*View).HalfPageDown, + "StartOfLine": (*View).StartOfLine, + "EndOfLine": (*View).EndOfLine, + "ToggleRuler": (*View).ToggleRuler, } keys := map[string]tcell.Key{ @@ -58,6 +64,26 @@ func InitBindings() { "Down": tcell.KeyDown, "Right": tcell.KeyRight, "Left": tcell.KeyLeft, + "AltUp": tcell.KeyAltUp, + "AltDown": tcell.KeyAltDown, + "AltLeft": tcell.KeyAltLeft, + "AltRight": tcell.KeyAltRight, + "CtrlUp": tcell.KeyCtrlUp, + "CtrlDown": tcell.KeyCtrlDown, + "CtrlLeft": tcell.KeyCtrlLeft, + "CtrlRight": tcell.KeyCtrlRight, + "ShiftUp": tcell.KeyShiftUp, + "ShiftDown": tcell.KeyShiftDown, + "ShiftLeft": tcell.KeyShiftLeft, + "ShiftRight": tcell.KeyShiftRight, + "AltShiftUp": tcell.KeyAltShiftUp, + "AltShiftDown": tcell.KeyAltShiftDown, + "AltShiftLeft": tcell.KeyAltShiftLeft, + "AltShiftRight": tcell.KeyAltShiftRight, + "CtrlShiftUp": tcell.KeyCtrlShiftUp, + "CtrlShiftDown": tcell.KeyCtrlShiftDown, + "CtrlShiftLeft": tcell.KeyCtrlShiftLeft, + "CtrlShiftRight": tcell.KeyCtrlShiftRight, "UpLeft": tcell.KeyUpLeft, "UpRight": tcell.KeyUpRight, "DownLeft": tcell.KeyDownLeft, @@ -209,35 +235,41 @@ func InitBindings() { // DefaultBindings returns a map containing micro's default keybindings func DefaultBindings() map[string]string { return map[string]string{ - "Up": "CursorUp", - "Down": "CursorDown", - "Right": "CursorRight", - "Left": "CursorLeft", - "Enter": "InsertEnter", - "Space": "InsertSpace", - "Backspace": "Backspace", - "Backspace2": "Backspace", - "Tab": "InsertTab", - "CtrlO": "OpenFile", - "CtrlS": "Save", - "CtrlF": "Find", - "CtrlN": "FindNext", - "CtrlP": "FindPrevious", - "CtrlZ": "Undo", - "CtrlY": "Redo", - "CtrlC": "Copy", - "CtrlX": "Cut", - "CtrlK": "CutLine", - "CtrlV": "Paste", - "CtrlA": "SelectAll", - "Home": "Beginning", - "End": "End", - "PgUp": "PageUp", - "PgDn": "PageDown", - "CtrlU": "HalfPageUp", - "CtrlD": "HalfPageDown", - "CtrlR": "ToggleRuler", - "Delete": "Delete", + "Up": "CursorUp", + "Down": "CursorDown", + "Right": "CursorRight", + "Left": "CursorLeft", + "ShiftLeft": "SelectLeft", + "ShiftRight": "SelectRight", + "AltLeft": "WordLeft", + "AltRight": "WordRight", + "AltShiftRight": "SelectWordRight", + "AltShiftLeft": "SelectWordLeft", + "Enter": "InsertEnter", + "Space": "InsertSpace", + "Backspace": "Backspace", + "Backspace2": "Backspace", + "Tab": "InsertTab", + "CtrlO": "OpenFile", + "CtrlS": "Save", + "CtrlF": "Find", + "CtrlN": "FindNext", + "CtrlP": "FindPrevious", + "CtrlZ": "Undo", + "CtrlY": "Redo", + "CtrlC": "Copy", + "CtrlX": "Cut", + "CtrlK": "CutLine", + "CtrlV": "Paste", + "CtrlA": "SelectAll", + "Home": "Beginning", + "End": "End", + "PgUp": "PageUp", + "PgDn": "PageDown", + "CtrlU": "HalfPageUp", + "CtrlD": "HalfPageDown", + "CtrlR": "ToggleRuler", + "Delete": "Delete", } } @@ -262,6 +294,56 @@ func (v *View) CursorLeft() bool { return true } +func (v *View) WordRight() bool { + v.cursor.WordRight() + return true +} + +func (v *View) WordLeft() bool { + v.cursor.WordLeft() + return true +} + +func (v *View) SelectLeft() bool { + loc := v.cursor.Loc() + if !v.cursor.HasSelection() { + v.cursor.origSelection[0] = loc + } + v.cursor.SelectTo(loc - 1) + v.cursor.Left() + return true +} + +func (v *View) SelectRight() bool { + loc := v.cursor.Loc() + if !v.cursor.HasSelection() { + v.cursor.origSelection[0] = loc + } + v.cursor.SelectTo(loc + 1) + v.cursor.Right() + return true +} + +func (v *View) SelectWordRight() bool { + loc := v.cursor.Loc() + if !v.cursor.HasSelection() { + v.cursor.origSelection[0] = loc + } + v.cursor.WordRight() + v.cursor.SelectTo(v.cursor.Loc()) + return true +} + +func (v *View) SelectWordLeft() bool { + loc := v.cursor.Loc() + if !v.cursor.HasSelection() { + v.cursor.origSelection[0] = loc + } + v.cursor.WordLeft() + v.cursor.SelectTo(v.cursor.Loc()) + return true +} + // CursorRight moves the cursor right func (v *View) CursorRight() bool { v.cursor.ResetSelection() diff --git a/cmd/micro/colorscheme.go b/cmd/micro/colorscheme.go index 67e8477e..597bc541 100644 --- a/cmd/micro/colorscheme.go +++ b/cmd/micro/colorscheme.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gdamore/tcell" + "github.com/zyedidia/tcell" "io/ioutil" "regexp" "strconv" diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 4e2ce558..4d2bd1f6 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -204,9 +204,36 @@ func (c *Cursor) AddWordToSelection() { } } +func (c *Cursor) SelectTo(loc int) { + if loc > c.origSelection[0] { + c.curSelection[0] = c.origSelection[0] + c.curSelection[1] = loc + 1 + } else { + c.curSelection[0] = loc + c.curSelection[1] = c.origSelection[0] + 1 + } +} + +func (c *Cursor) WordRight() { + for IsWordChar(string(c.RuneUnder(c.x))) { + c.Right() + } + c.Right() +} + +func (c *Cursor) WordLeft() { + for IsWordChar(string(c.RuneUnder(c.x))) { + c.Left() + } + c.Left() +} + // RuneUnder returns the rune under the given x position func (c *Cursor) RuneUnder(x int) rune { line := []rune(c.v.buf.lines[c.y]) + if len(line) == 0 { + return '\n' + } if x >= len(line) { x = len(line) - 1 } else if x < 0 { diff --git a/cmd/micro/highlighter.go b/cmd/micro/highlighter.go index 5acec698..077e2879 100644 --- a/cmd/micro/highlighter.go +++ b/cmd/micro/highlighter.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/zyedidia/tcell" "io/ioutil" "path/filepath" "regexp" diff --git a/cmd/micro/messenger.go b/cmd/micro/messenger.go index c3bfd1cc..10108820 100644 --- a/cmd/micro/messenger.go +++ b/cmd/micro/messenger.go @@ -7,7 +7,7 @@ import ( "os" "strconv" - "github.com/gdamore/tcell" + "github.com/zyedidia/tcell" ) // TermMessage sends a message to the user in the terminal. This usually occurs before diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index fb421b24..4b8aa786 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -6,8 +6,8 @@ import ( "io/ioutil" "os" - "github.com/gdamore/tcell" - "github.com/gdamore/tcell/encoding" + "github.com/zyedidia/tcell" + "github.com/zyedidia/tcell/encoding" "github.com/go-errors/errors" "github.com/mattn/go-isatty" "github.com/mitchellh/go-homedir" diff --git a/cmd/micro/search.go b/cmd/micro/search.go index f5efce61..77c368af 100644 --- a/cmd/micro/search.go +++ b/cmd/micro/search.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gdamore/tcell" + "github.com/zyedidia/tcell" "regexp" ) diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 545dad22..6a85c3d5 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" + "github.com/zyedidia/tcell" ) // The View struct stores information about a view into a buffer.