fix(textarea): reset lastCharOffset if not moving vertically

This commit is contained in:
Maas Lalani 2022-08-11 17:33:14 -04:00
parent 0f1a912f12
commit e691e35a6d
No known key found for this signature in database
GPG Key ID: 5A6ED5CBF1A0A000

View File

@ -238,8 +238,6 @@ func (m *Model) insertUpdate(msg tea.Msg) tea.Cmd {
} }
func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd { func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd {
var cmd tea.Cmd
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
if m.command.IsSeeking() { if m.command.IsSeeking() {
@ -302,6 +300,11 @@ func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd {
m.command = &NormalCommand{} m.command = &NormalCommand{}
break break
} }
if !strings.ContainsAny(msg.String(), "jk") {
m.lastCharOffset = 0
}
switch msg.String() { switch msg.String() {
case "esc": case "esc":
m.command = &NormalCommand{} m.command = &NormalCommand{}
@ -466,7 +469,6 @@ func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd {
if msg.String() == "h" { if msg.String() == "h" {
direction = -1 direction = -1
} }
m.lastCharOffset = 0
m.command.Range = Range{ m.command.Range = Range{
Start: Position{m.row, m.col}, Start: Position{m.row, m.col},
End: Position{m.row, clamp(m.col+(direction*max(m.command.Count, 1)), 0, len(m.value[m.row]))}, End: Position{m.row, clamp(m.col+(direction*max(m.command.Count, 1)), 0, len(m.value[m.row]))},
@ -515,20 +517,15 @@ func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd {
m.command = &NormalCommand{} m.command = &NormalCommand{}
return nil return nil
case "p": case "p":
cmd = Paste return Paste
} }
if !strings.ContainsAny(msg.String(), "jk") {
m.lastCharOffset = 0
}
case executeMsg: case executeMsg:
switch m.command.Action { switch m.command.Action {
case ActionDelete: case ActionDelete:
m.deleteRange(m.command.Range) m.deleteRange(m.command.Range)
case ActionChange: case ActionChange:
m.deleteRange(m.command.Range) m.deleteRange(m.command.Range)
cmd = m.SetMode(ModeInsert) return m.SetMode(ModeInsert)
case ActionMove: case ActionMove:
m.row = clamp(m.command.Range.End.Row, 0, len(m.value)-1) m.row = clamp(m.command.Range.End.Row, 0, len(m.value)-1)
m.col = clamp(m.command.Range.End.Col, 0, len(m.value[m.row])) m.col = clamp(m.command.Range.End.Col, 0, len(m.value[m.row]))
@ -539,7 +536,7 @@ func (m *Model) normalUpdate(msg tea.Msg) tea.Cmd {
m.handlePaste(string(msg)) m.handlePaste(string(msg))
} }
return cmd return nil
} }
func (m *Model) findCharLeft(r rune) Position { func (m *Model) findCharLeft(r rune) Position {