Starting to add more mappings for arrow keys

These mappings include Alt+arrows and Shift+arrows and Alt+Shift+arrows

This commit also switches the version of tcell that micro uses to my
fork which supports alt, shift, and ctrl + arrows.
This commit is contained in:
Zachary Yedidia
2016-04-25 21:23:03 -04:00
parent 0ee6be3d0f
commit e00e0cfa3f
8 changed files with 176 additions and 67 deletions

View File

@@ -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()

View File

@@ -2,7 +2,7 @@ package main
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/zyedidia/tcell"
"io/ioutil"
"regexp"
"strconv"

View File

@@ -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 {

View File

@@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/zyedidia/tcell"
"io/ioutil"
"path/filepath"
"regexp"

View File

@@ -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

View File

@@ -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"

View File

@@ -1,7 +1,7 @@
package main
import (
"github.com/gdamore/tcell"
"github.com/zyedidia/tcell"
"regexp"
)

View File

@@ -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.