From 8624776d4572078ae6ff098d454c719047f9eb83 Mon Sep 17 00:00:00 2001 From: Mikael Fangel <34864484+MikaelFangel@users.noreply.github.com> Date: Thu, 5 Dec 2024 22:40:33 +0100 Subject: [PATCH] fix(textinput): slicing outside cap (#532) * textinput: fix slicing outside cap * textinput: add test that makes slicing outside cap occur * chore: tidy with gofmt --------- Co-authored-by: bashbunni --- textinput/textinput.go | 4 +++- textinput/textinput_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index d1abf1247..66e451859 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -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() diff --git a/textinput/textinput_test.go b/textinput/textinput_test.go index 27a7640a8..95ef0c616 100644 --- a/textinput/textinput_test.go +++ b/textinput/textinput_test.go @@ -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() +}