summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-05-26 12:27:59 +1000
committerJesse Duffield <jessedduffield@gmail.com>2019-05-26 12:42:17 +1000
commitc039e5bed06192ad536e07da7cf89a2502070a1d (patch)
tree4cbf1d96497557f9e7cccf6b5d0674679fef0159 /vendor
parent527c025a0c6a445230b88dfa2d4197554e5fc130 (diff)
support going to start/end of line and deleting lines in simple editor
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/jesseduffield/gocui/edit.go64
-rw-r--r--vendor/github.com/jesseduffield/gocui/gui.go2
-rw-r--r--vendor/github.com/jesseduffield/gocui/view.go11
3 files changed, 68 insertions, 9 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/edit.go b/vendor/github.com/jesseduffield/gocui/edit.go
index b99f74f93..f8eb08a57 100644
--- a/vendor/github.com/jesseduffield/gocui/edit.go
+++ b/vendor/github.com/jesseduffield/gocui/edit.go
@@ -33,18 +33,10 @@ var DefaultEditor Editor = EditorFunc(simpleEditor)
// simpleEditor is used as the default gocui editor.
func simpleEditor(v *View, key Key, ch rune, mod Modifier) {
switch {
- case ch != 0 && mod == 0:
- v.EditWrite(ch)
- case key == KeySpace:
- v.EditWrite(' ')
case key == KeyBackspace || key == KeyBackspace2:
v.EditDelete(true)
case key == KeyDelete:
v.EditDelete(false)
- case key == KeyInsert:
- v.Overwrite = !v.Overwrite
- case key == KeyEnter:
- v.EditNewLine()
case key == KeyArrowDown:
v.MoveCursor(0, 1, false)
case key == KeyArrowUp:
@@ -53,6 +45,20 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) {
v.MoveCursor(-1, 0, false)
case key == KeyArrowRight:
v.MoveCursor(1, 0, false)
+ case key == KeyTab:
+ v.EditNewLine()
+ case key == KeySpace:
+ v.EditWrite(' ')
+ case key == KeyInsert:
+ v.Overwrite = !v.Overwrite
+ case key == KeyCtrlU:
+ v.EditDeleteToStartOfLine()
+ case key == KeyCtrlA:
+ v.EditGotoToStartOfLine()
+ case key == KeyCtrlE:
+ v.EditGotoToEndOfLine()
+ default:
+ v.EditWrite(ch)
}
}
@@ -63,6 +69,48 @@ func (v *View) EditWrite(ch rune) {
v.moveCursor(w, 0, true)
}
+// EditDeleteToStartOfLine is the equivalent of pressing ctrl+U in your terminal, it deletes to the end of the line. Or if you are already at the start of the line, it deletes the newline character
+func (v *View) EditDeleteToStartOfLine() {
+ x, _ := v.Cursor()
+ if x == 0 {
+ v.EditDelete(true)
+ } else {
+ // delete characters until we are the start of the line
+ for x > 0 {
+ v.EditDelete(true)
+ x, _ = v.Cursor()
+ }
+ }
+}
+
+// EditGotoToStartOfLine takes you to the start of the current line
+func (v *View) EditGotoToStartOfLine() {
+ x, _ := v.Cursor()
+ for x > 0 {
+ v.MoveCursor(-1, 0, false)
+ x, _ = v.Cursor()
+ }
+}
+
+// EditGotoToEndOfLine takes you to the end of the line
+func (v *View) EditGotoToEndOfLine() {
+ _, y := v.Cursor()
+ _ = v.SetCursor(0, y+1)
+ x, newY := v.Cursor()
+ if newY == y {
+ // we must be on the last line, so lets move to the very end
+ prevX := -1
+ for prevX != x {
+ prevX = x
+ v.MoveCursor(1, 0, false)
+ x, _ = v.Cursor()
+ }
+ } else {
+ // most left so now we're at the end of the original line
+ v.MoveCursor(-1, 0, false)
+ }
+}
+
// EditDelete deletes a rune at the cursor position. back determines the
// direction.
func (v *View) EditDelete(back bool) {
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go
index cd22d3d00..37e46cc0f 100644
--- a/vendor/github.com/jesseduffield/gocui/gui.go
+++ b/vendor/github.com/jesseduffield/gocui/gui.go
@@ -733,7 +733,7 @@ func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err err
if kb.matchView(v) {
return g.execKeybinding(v, kb)
}
- if kb.viewName == "" && ((v != nil && !v.Editable) || kb.ch == 0) {
+ if kb.viewName == "" && ((v != nil && !v.Editable) || (kb.ch == 0 && kb.key != KeyCtrlU && kb.key != KeyCtrlA && kb.key != KeyCtrlE)) {
globalKb = kb
}
}
diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go
index 7cf632c84..9d6553cbc 100644
--- a/vendor/github.com/jesseduffield/gocui/view.go
+++ b/vendor/github.com/jesseduffield/gocui/view.go
@@ -8,6 +8,7 @@ import (
"bytes"
"io"
"strings"
+ "sync"
"time"
"github.com/go-errors/errors"
@@ -91,6 +92,8 @@ type View struct {
// If HasLoader is true, the message will be appended with a spinning loader animation
HasLoader bool
+
+ writeMutex sync.Mutex
}
type viewLine struct {
@@ -224,6 +227,8 @@ func (v *View) Origin() (x, y int) {
// be called to clear the view's buffer.
func (v *View) Write(p []byte) (n int, err error) {
v.tainted = true
+ v.writeMutex.Lock()
+ defer v.writeMutex.Unlock()
for _, ch := range bytes.Runes(p) {
switch ch {
@@ -250,6 +255,7 @@ func (v *View) Write(p []byte) (n int, err error) {
}
}
}
+
return len(p), nil
}
@@ -603,3 +609,8 @@ func Loader() cell {
chr: chr,
}
}
+
+// IsTainted tells us if the view is tainted
+func (v *View) IsTainted() bool {
+ return v.tainted
+}