mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-01 22:10:23 +00:00
fix(editor): handle UTF-8 characters properly in SetValueWithAttachments (#1469)
This commit is contained in:
parent
c5368e7412
commit
e4e0b8fd34
1 changed files with 12 additions and 7 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/v2/spinner"
|
"github.com/charmbracelet/bubbles/v2/spinner"
|
||||||
tea "github.com/charmbracelet/bubbletea/v2"
|
tea "github.com/charmbracelet/bubbletea/v2"
|
||||||
|
|
@ -524,14 +525,18 @@ func (m *editorComponent) SetValueWithAttachments(value string) {
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for i < len(value) {
|
for i < len(value) {
|
||||||
|
r, size := utf8.DecodeRuneInString(value[i:])
|
||||||
// Check if filepath and add attachment
|
// Check if filepath and add attachment
|
||||||
if value[i] == '@' {
|
if r == '@' {
|
||||||
start := i + 1
|
start := i + size
|
||||||
end := start
|
end := start
|
||||||
for end < len(value) && value[end] != ' ' && value[end] != '\t' && value[end] != '\n' && value[end] != '\r' {
|
for end < len(value) {
|
||||||
end++
|
nextR, nextSize := utf8.DecodeRuneInString(value[end:])
|
||||||
|
if nextR == ' ' || nextR == '\t' || nextR == '\n' || nextR == '\r' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
end += nextSize
|
||||||
}
|
}
|
||||||
|
|
||||||
if end > start {
|
if end > start {
|
||||||
filePath := value[start:end]
|
filePath := value[start:end]
|
||||||
slog.Debug("test", "filePath", filePath)
|
slog.Debug("test", "filePath", filePath)
|
||||||
|
|
@ -548,8 +553,8 @@ func (m *editorComponent) SetValueWithAttachments(value string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a valid file path, insert the character normally
|
// Not a valid file path, insert the character normally
|
||||||
m.textarea.InsertRune(rune(value[i]))
|
m.textarea.InsertRune(r)
|
||||||
i++
|
i += size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue