aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()