summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorAlexey Yerin <yyp@disroot.org>2021-04-27 19:23:26 +0300
committerHubert Hirtz <hubert@hirtz.pm>2021-04-27 19:32:20 +0200
commitd12564cc5e2b145f7c6d4122b98dbe2ac9ea620e (patch)
tree840089a2b24fba046463edc35f07076fc98fbba9 /ui
parentAdd BUFFER command to jump to the matching buffer (diff)
editor: Ctrl+{Right,Left} moves cursor by words
A very useful readline feature when combined with ^W can be a really quick way to reformat a sentence, which is what I do on IRC quite often.
Diffstat (limited to '')
-rw-r--r--ui/editor.go31
-rw-r--r--ui/ui.go8
2 files changed, 39 insertions, 0 deletions
diff --git a/ui/editor.go b/ui/editor.go
index 5419eaa..a36fb1a 100644
--- a/ui/editor.go
+++ b/ui/editor.go
@@ -180,6 +180,21 @@ func (e *Editor) right() {
}
}
+func (e *Editor) RightWord() {
+ line := e.text[e.lineIdx]
+
+ if e.cursorIdx == len(line) {
+ return
+ }
+
+ for line[e.cursorIdx] == ' ' {
+ e.Right()
+ }
+ for i := e.cursorIdx; i < len(line) && line[i] != ' '; i += 1 {
+ e.Right()
+ }
+}
+
func (e *Editor) Left() {
if e.cursorIdx == 0 {
return
@@ -191,6 +206,22 @@ func (e *Editor) Left() {
e.offsetIdx = 0
}
}
+}
+
+func (e *Editor) LeftWord() {
+ if e.cursorIdx == 0 {
+ return
+ }
+
+ line := e.text[e.lineIdx]
+
+ for line[e.cursorIdx - 1] == ' ' {
+ e.Left()
+ }
+ for i := e.cursorIdx - 1; i >= 0 && line[i] != ' '; i -= 1 {
+ e.Left()
+ }
+
e.autoCache = nil
}
diff --git a/ui/ui.go b/ui/ui.go
index 9ab9024..86608d1 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -176,10 +176,18 @@ func (ui *UI) InputRight() {
ui.e.Right()
}
+func (ui *UI) InputRightWord() {
+ ui.e.RightWord()
+}
+
func (ui *UI) InputLeft() {
ui.e.Left()
}
+func (ui *UI) InputLeftWord() {
+ ui.e.LeftWord()
+}
+
func (ui *UI) InputHome() {
ui.e.Home()
}