diff --git a/textarea/textarea.go b/textarea/textarea.go index 26d3eef..0db907c 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -743,7 +743,7 @@ func (m *Model) deleteWordLeft() { // Linter note: it's critical that we acquire the initial cursor position // here prior to altering it via SetCursor() below. As such, moving this // call into the corresponding if clause does not apply here. - oldCol := m.col //nolint:ifshort + oldCol := m.col m.SetCursorColumn(m.col - 1) for unicode.IsSpace(m.value[m.row][m.col]) { @@ -1383,14 +1383,13 @@ func (m Model) placeholderView() string { case i == 0: // first character of first line as cursor with character m.virtualCursor.TextStyle = styles.computedPlaceholder() - m.virtualCursor.SetChar(string(plines[0][0])) + + ch, rest, _, _ := uniseg.FirstGraphemeClusterInString(plines[0], 0) + m.virtualCursor.SetChar(ch) s.WriteString(lineStyle.Render(m.virtualCursor.View())) // the rest of the first line - placeholderTail := plines[0][1:] - gap := strings.Repeat(" ", max(0, m.width-uniseg.StringWidth(plines[0]))) - renderedPlaceholder := styles.computedPlaceholder().Render(placeholderTail + gap) - s.WriteString(lineStyle.Render(renderedPlaceholder)) + s.WriteString(lineStyle.Render(styles.computedPlaceholder().Render(rest))) // remaining lines case len(plines) > i: // current line placeholder text diff --git a/textarea/textarea_test.go b/textarea/textarea_test.go index 774067b..d1ccad5 100644 --- a/textarea/textarea_test.go +++ b/textarea/textarea_test.go @@ -1671,6 +1671,26 @@ func TestView(t *testing.T) { `), }, }, + { + name: "placeholder chinese character", + modelFunc: func(m Model) Model { + m.Placeholder = "输入消息..." + m.ShowLineNumbers = true + m.SetWidth(20) + return m + }, + want: want{ + view: heredoc.Doc(` + > 1 输入消息... + > + > + > + > + > + + `), + }, + }, } for _, tt := range tests { diff --git a/textinput/textinput.go b/textinput/textinput.go index 539c174..acf966c 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -397,7 +397,7 @@ func (m *Model) deleteWordBackward() { // Linter note: it's critical that we acquire the initial cursor position // here prior to altering it via SetCursor() below. As such, moving this // call into the corresponding if clause does not apply here. - oldPos := m.pos //nolint:ifshort + oldPos := m.pos m.SetCursor(m.pos - 1) for unicode.IsSpace(m.value[m.pos]) {