diff --git a/key/key.go b/key/key.go index 0c79a7a2e..db10f20bb 100644 --- a/key/key.go +++ b/key/key.go @@ -36,7 +36,10 @@ // to render help text for keystrokes in your views. package key -import "fmt" +import ( + "fmt" + "slices" +) // Binding describes a set of keybindings and, optionally, their associated // help text. @@ -80,6 +83,15 @@ func WithDisabled() BindingOpt { } } +func (b Binding) Equal(o Binding) bool { + keysEqual := slices.Equal(slices.Sorted(slices.Values(b.keys)), slices.Sorted(slices.Values(o.keys))) + helpsEqual := b.help == o.help + if keysEqual && helpsEqual { + return true + } + return false +} + // SetKeys sets the keys for the keybinding. func (b *Binding) SetKeys(keys ...string) { b.keys = keys diff --git a/textarea/textarea.go b/textarea/textarea.go index 26d3eefd2..41e4d1fde 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -1391,6 +1391,7 @@ func (m Model) placeholderView() string { gap := strings.Repeat(" ", max(0, m.width-uniseg.StringWidth(plines[0]))) renderedPlaceholder := styles.computedPlaceholder().Render(placeholderTail + gap) s.WriteString(lineStyle.Render(renderedPlaceholder)) + // remaining lines case len(plines) > i: // current line placeholder text diff --git a/textarea/textarea_test.go b/textarea/textarea_test.go index 774067bb0..1bd7640b5 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 { @@ -1689,6 +1709,7 @@ func TestView(t *testing.T) { wantView := stripString(tt.want.view) if view != wantView { + t.Log(udiff.Unified("expected", "got", wantView, view)) t.Fatalf("Want:\n%v\nGot:\n%v\n", wantView, view) }