mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 06:17:12 +09:00
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:
@@ -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()
|
||||
|
||||
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/zyedidia/tcell"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/zyedidia/tcell"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/zyedidia/tcell"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user