Skip to content

Commit

Permalink
fix(textinput): slicing outside cap (#532)
Browse files Browse the repository at this point in the history
* textinput: fix slicing outside cap

* textinput: add test that makes slicing outside cap occur

* chore: tidy with gofmt

---------

Co-authored-by: bashbunni <bunni@bashbunni.dev>
  • Loading branch information
MikaelFangel and bashbunni authored Dec 5, 2024
1 parent e5296a2 commit 8624776
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,12 @@ func (m Model) View() string {
func (m Model) placeholderView() string {
var (
v string
p = []rune(m.Placeholder)
style = m.PlaceholderStyle.Inline(true).Render
)

p := make([]rune, m.Width+1)
copy(p, []rune(m.Placeholder))

m.Cursor.TextStyle = m.PlaceholderStyle
m.Cursor.SetChar(string(p[:1]))
v += m.Cursor.View()
Expand Down
7 changes: 7 additions & 0 deletions textinput/textinput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ func Test_CurrentSuggestion(t *testing.T) {
t.Fatalf("Error: expected first suggestion but was %s", suggestion)
}
}

func Test_SlicingOutsideCap(t *testing.T) {
textinput := New()
textinput.Placeholder = "作業ディレクトリを指定してください"
textinput.Width = 32
textinput.View()
}

0 comments on commit 8624776

Please sign in to comment.