Fix keypad input not working in TUI textarea component

This commit is contained in:
neominik 2025-06-29 18:36:07 +02:00
parent a4beb60e19
commit 5cf02787dc
2 changed files with 60 additions and 3 deletions

View file

@ -33,6 +33,45 @@ const (
maxLines = 10000 maxLines = 10000
) )
func keypadToChar(keyString string) string {
switch keyString {
case "kp0":
return "0"
case "kp1":
return "1"
case "kp2":
return "2"
case "kp3":
return "3"
case "kp4":
return "4"
case "kp5":
return "5"
case "kp6":
return "6"
case "kp7":
return "7"
case "kp8":
return "8"
case "kp9":
return "9"
case "kpplus":
return "+"
case "kpminus":
return "-"
case "kpmul":
return "*"
case "kpdiv":
return "/"
case "kpperiod":
return "."
case "kpequal":
return "="
default:
return ""
}
}
// Helper functions for converting between runes and any slices // Helper functions for converting between runes and any slices
// runesToInterfaces converts a slice of runes to a slice of interfaces // runesToInterfaces converts a slice of runes to a slice of interfaces
@ -1673,7 +1712,14 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.transposeLeft() m.transposeLeft()
default: default:
m.InsertRunesFromUserInput([]rune(msg.Text)) // Handle keypad keys by converting them to their character equivalents
if msg.Text == "" {
if char := keypadToChar(msg.String()); char != "" {
m.InsertRunesFromUserInput([]rune(char))
}
} else {
m.InsertRunesFromUserInput([]rune(msg.Text))
}
} }
case pasteMsg: case pasteMsg:

View file

@ -105,6 +105,17 @@ func (a Model) Init() tea.Cmd {
return tea.Batch(cmds...) return tea.Batch(cmds...)
} }
func isKeypadKey(keyString string) bool {
switch keyString {
case "kp0", "kp1", "kp2", "kp3", "kp4",
"kp5", "kp6", "kp7", "kp8", "kp9",
"kpplus", "kpminus", "kpmul", "kpdiv",
"kpperiod", "kpenter", "kpequal":
return true
default:
return false
}
}
func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd var cmd tea.Cmd
var cmds []tea.Cmd var cmds []tea.Cmd
@ -267,8 +278,8 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return a, tea.Batch(cmds...) return a, tea.Batch(cmds...)
} }
// 4. Maximize editor responsiveness for printable characters // 4. Maximize editor responsiveness for printable characters and keypad keys
if msg.Text != "" { if msg.Text != "" || isKeypadKey(keyString) {
updated, cmd := a.editor.Update(msg) updated, cmd := a.editor.Update(msg)
a.editor = updated.(chat.EditorComponent) a.editor = updated.(chat.EditorComponent)
cmds = append(cmds, cmd) cmds = append(cmds, cmd)