aboutsummaryrefslogtreecommitdiff
path: root/view.go
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-23 19:34:14 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-23 19:34:14 +0100
commit6ba65a24c45ae55e0af5ad9c0b7d65155f551211 (patch)
tree9bdba649cc269de0fd3114aa0f225ad4e575b2a6 /view.go
parentce20fc8a9d249798e9349679b37d9452ee14c3e0 (diff)
downloadpoe-6ba65a24c45ae55e0af5ad9c0b7d65155f551211.tar.gz
poe-6ba65a24c45ae55e0af5ad9c0b7d65155f551211.tar.bz2
poe-6ba65a24c45ae55e0af5ad9c0b7d65155f551211.zip
Implement ^W using PrevWord().
Diffstat (limited to 'view.go')
-rw-r--r--view.go30
1 files changed, 7 insertions, 23 deletions
diff --git a/view.go b/view.go
index ff272a6..d0e6bba 100644
--- a/view.go
+++ b/view.go
@@ -402,30 +402,14 @@ func (v *View) HandleEvent(ev tcell.Event) {
v.Delete()
return
case tcell.KeyCtrlW: // delete word backwards
- offset := v.text.q0 - 1
- c, _ := v.text.buf.ByteAt(offset)
- if unicode.IsSpace(rune(c)) {
- if c == '\n' {
- v.Delete()
- return
- }
- for unicode.IsSpace(rune(c)) && c != '\n' {
- v.Delete()
- if v.text.q0 <= 0 {
- break
- }
- offset--
- c, _ = v.text.buf.ByteAt(offset)
- }
- }
- for !unicode.IsSpace(rune(c)) {
- v.Delete()
- if v.text.q0 <= 0 {
- break
- }
- offset--
- c, _ = v.text.buf.ByteAt(offset)
+ startpos := v.Cursor()
+ offset := v.text.PrevWord(v.Cursor())
+ if offset == 0 {
+ v.SetCursor(-1, io.SeekCurrent)
+ offset = v.text.PrevWord(v.Cursor())
}
+ v.text.SetDot(v.Cursor()-offset, startpos)
+ v.Delete()
return
case tcell.KeyCtrlZ:
v.text.Undo()