diff --git a/textinput/textinput.go b/textinput/textinput.go index 5146c62..501f9a7 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -13,6 +13,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" rw "github.com/mattn/go-runewidth" + "github.com/rivo/uniseg" ) // Internal messages for clipboard operations. @@ -332,7 +333,7 @@ func (m *Model) insertRunesFromUserInput(v []rune) { // If a max width is defined, perform some logic to treat the visible area // as a horizontally scrolling viewport. func (m *Model) handleOverflow() { - if m.Width <= 0 || rw.StringWidth(string(m.value)) <= m.Width { + if m.Width <= 0 || uniseg.StringWidth(string(m.value)) <= m.Width { m.offset = 0 m.offsetRight = len(m.value) return @@ -541,7 +542,7 @@ func (m *Model) wordForward() { func (m Model) echoTransform(v string) string { switch m.EchoMode { case EchoPassword: - return strings.Repeat(string(m.EchoCharacter), rw.StringWidth(v)) + return strings.Repeat(string(m.EchoCharacter), uniseg.StringWidth(v)) case EchoNone: return "" case EchoNormal: @@ -688,7 +689,7 @@ func (m Model) View() string { // If a max width and background color were set fill the empty spaces with // the background color. - valWidth := rw.StringWidth(string(value)) + valWidth := uniseg.StringWidth(string(value)) if m.Width > 0 && valWidth <= m.Width { padding := max(0, m.Width-valWidth) if valWidth+padding <= m.Width && pos < len(value) {