chore(textarea): move completion check

This commit is contained in:
Christian Rocha
2025-02-01 07:19:54 -05:00
parent 88778ca59d
commit 644c7b3398
+12 -11
View File
@@ -1092,17 +1092,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil
}
// Need to check for completion before, because key is configurable and might be double assigned
keyMsg, ok := msg.(tea.KeyMsg)
if ok && key.Matches(keyMsg, m.KeyMap.AcceptSuggestion) {
if m.canAcceptSuggestion() {
m.value = m.matchedSuggestions[m.currentSuggestionIndex]
m.format()
m.row = len(m.value) - 1
m.CursorEnd()
}
}
// Used to determine if the cursor should blink.
oldRow, oldCol := m.cursorLineNumber(), m.col
@@ -1119,7 +1108,19 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.PasteMsg:
m.insertRunesFromUserInput([]rune(msg))
case tea.KeyPressMsg:
// We need to check for completion before checking other key matches,
// because the key is configurable and might be double assigned.
if key.Matches(msg, m.KeyMap.AcceptSuggestion) {
if m.canAcceptSuggestion() {
m.value = m.matchedSuggestions[m.currentSuggestionIndex]
m.format()
m.row = len(m.value) - 1
m.CursorEnd()
}
}
switch {
case key.Matches(msg, m.KeyMap.DeleteAfterCursor):
m.col = clamp(m.col, 0, len(m.value[m.row]))