From 0f1a912f124373255ccc36081d9cd61919b05ccb Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 11 Aug 2022 17:13:26 -0400 Subject: [PATCH] fix: edge cases with {d,c}iw and {d,c}aw --- textarea/modal.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/textarea/modal.go b/textarea/modal.go index e39d811..8848b8b 100644 --- a/textarea/modal.go +++ b/textarea/modal.go @@ -246,6 +246,10 @@ func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd { if len(msg.Runes) <= 0 { m.command = &NormalCommand{} } + if msg.Runes[0] == 'w' || msg.Runes[0] == 'W' { + m.command.Range = m.findPairRange(msg.Runes[0]) + return executeCmd(*m.command) + } switch m.command.Buffer { case "a": m.command.Range = m.findPairRange(msg.Runes[0]) @@ -554,10 +558,10 @@ func (m *Model) findCharRight(r rune) Position { col := m.col for col < len(m.value[m.row]) { - col++ if m.value[m.row][col] == r { return Position{m.row, col} } + col++ } return Position{m.row, m.col} } @@ -604,6 +608,13 @@ func (m *Model) findWordLeft(count int, ignorePunctuation bool) Position { wordBreak = isWordBreak } + if count == 0 { + if wordBreak(m.value[m.row][m.col-1]) { + return Position{m.row, m.col} + } + count = 1 + } + row, col := m.row, m.col for count > 0 {