Skip to content

Commit

Permalink
rune
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Aug 22, 2024
1 parent 1eaa077 commit d41edef
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/io/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ func (u *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return u, nil
}

u.Keyword = u.Keyword[:len(u.Keyword)-1]
keywordRunes := []rune(u.Keyword)
keywordRunes = keywordRunes[:len(keywordRunes)-1]
u.Keyword = string(keywordRunes)
u.Filtered = u.Filtered.Prev
cnt := 0
for i := range u.Choices {
Expand All @@ -187,20 +189,23 @@ func (u *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyRunes:
str := msg.String()
if !msg.Paste {
u.addCharacter(str)
for _, r := range str {
u.addCharacter(string(r))
}
} else {
if strings.Contains(str, string('\n')) || strings.Contains(str, string('\r')) {
u.IsEntered = true
return u, tea.Quit
}

for i := range len(str) {
runes := []rune(str)
for i, r := range runes {
// characters by paste key are enclosed by '[' and ']'
if i == 0 || i == len(str)-1 {
if i == 0 || i == len(runes)-1 {
continue
}
if str[i] != ' ' && str[i] != '\t' {
u.addCharacter(string(str[i]))
if r != ' ' && r != '\t' {
u.addCharacter(string(r))
}
}
}
Expand Down

0 comments on commit d41edef

Please sign in to comment.