Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions textarea/textarea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down