diff options
author | Ghislain Rodrigues <git@ghislain-rodrigues.fr> | 2021-03-31 11:08:27 +0200 |
---|---|---|
committer | Mateusz CzapliĆski <czapkofan@gmail.com> | 2021-04-27 09:22:47 +0200 |
commit | 840f23c21d3e692661d6ee574490880d7524f761 (patch) | |
tree | a1f56eefbb9d9af07ea9ffdc3616bbf15fb0489d /up.go | |
parent | 88516fde4023aafa335f8da0a12a95bab0f8033a (diff) |
unix-word-rubout erases all the characters before the cursor
until finding either a space or a BOL.
Diffstat (limited to 'up.go')
-rw-r--r-- | up.go | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -30,6 +30,7 @@ import ( "os" "os/exec" "sync" + "unicode" "github.com/gdamore/tcell" "github.com/gdamore/tcell/terminfo" @@ -97,7 +98,7 @@ If a plus '+' is visible in top-left corner, the internal buffer limit KEYS -- alphanumeric & symbol keys, Left, Right, Ctrl-A/E/B/F/K/Y +- alphanumeric & symbol keys, Left, Right, Ctrl-A/E/B/F/K/Y/W - navigate and edit the pipeline command - Enter - execute the pipeline command, updating the pipeline output panel - Up, Dn, PgUp, PgDn, Ctrl-Left, Ctrl-Right @@ -419,6 +420,9 @@ func (e *Editor) HandleKey(ev *tcell.EventKey) bool { case key(tcell.KeyCtrlY), ctrlKey(tcell.KeyCtrlY): e.insert(e.killspace...) + case key(tcell.KeyCtrlW), + ctrlKey(tcell.KeyCtrlW): + e.unixWordRubout() default: // Unknown key/combination, not handled return false @@ -450,6 +454,22 @@ func (e *Editor) kill() { e.value = e.value[:e.cursor] } +// unixWordRubout removes the part of the word on the left of the cursor. A word is +// delimited by whitespaces. +// The term `unix-word-rubout` comes from `readline` (see `man 3 readline`) +func (e *Editor) unixWordRubout() { + if e.cursor <= 0 { + return + } + pos := e.cursor - 1 + for pos != 0 && (unicode.IsSpace(e.value[pos]) || !unicode.IsSpace(e.value[pos-1])) { + pos-- + } + e.killspace = append(e.killspace[:0], e.value[pos:e.cursor]...) + e.value = append(e.value[:pos], e.value[e.cursor:]...) + e.cursor = pos +} + type BufView struct { // TODO: Wrap bool Y int // Y of the view in the Buf, for down/up scrolling |