diff options
| author | neolooong <[email protected]> | 2025-07-31 23:45:43 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-31 10:45:43 -0500 |
| commit | e4e0b8fd344273f48ef66e68d9626de80111cc0b (patch) | |
| tree | a55fb90cb5642ae8215fc4f2f067c09187fa046a | |
| parent | c5368e74128560a749ea0996e4668c523fadd8e0 (diff) | |
| download | opencode-e4e0b8fd344273f48ef66e68d9626de80111cc0b.tar.gz opencode-e4e0b8fd344273f48ef66e68d9626de80111cc0b.zip | |
fix(editor): handle UTF-8 characters properly in SetValueWithAttachments (#1469)
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 677d903fd..1263a6e72 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -8,6 +8,7 @@ import ( "path/filepath" "strconv" "strings" + "unicode/utf8" "github.com/charmbracelet/bubbles/v2/spinner" tea "github.com/charmbracelet/bubbletea/v2" @@ -524,14 +525,18 @@ func (m *editorComponent) SetValueWithAttachments(value string) { i := 0 for i < len(value) { + r, size := utf8.DecodeRuneInString(value[i:]) // Check if filepath and add attachment - if value[i] == '@' { - start := i + 1 + if r == '@' { + start := i + size end := start - for end < len(value) && value[end] != ' ' && value[end] != '\t' && value[end] != '\n' && value[end] != '\r' { - end++ + for end < len(value) { + nextR, nextSize := utf8.DecodeRuneInString(value[end:]) + if nextR == ' ' || nextR == '\t' || nextR == '\n' || nextR == '\r' { + break + } + end += nextSize } - if end > start { filePath := value[start:end] slog.Debug("test", "filePath", filePath) @@ -548,8 +553,8 @@ func (m *editorComponent) SetValueWithAttachments(value string) { } // Not a valid file path, insert the character normally - m.textarea.InsertRune(rune(value[i])) - i++ + m.textarea.InsertRune(r) + i += size } } |
