From 29bf309a98590ff59ead588abb96af340f92c6f1 Mon Sep 17 00:00:00 2001 From: nobe4 Date: Wed, 2 Oct 2024 13:14:10 +0200 Subject: [PATCH] feat(textinput): expose `UpdateSuggestions` method This enables clients of the lib to update the suggestions at runtime whenever they please. One direct application of this is when using `m.SetValue()`: After calling it, there is no way to get the updated `m.CurrentSuggestion()` as `m.SetValue()` does not update the suggestion list. It would be possible to also run `m.updateSuggestions()` somewhere in `m.SetValue`, but that might interfere with other things. --- textinput/textinput.go | 8 ++++---- textinput/textinput_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/textinput/textinput.go b/textinput/textinput.go index cf944b89..f2f3ce53 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -262,7 +262,7 @@ func (m *Model) SetSuggestions(suggestions []string) { m.suggestions[i] = []rune(s) } - m.updateSuggestions() + m.UpdateSuggestions() } // rsan initializes or retrieves the rune sanitizer. @@ -621,7 +621,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // Check again if can be completed // because value might be something that does not match the completion prefix - m.updateSuggestions() + m.UpdateSuggestions() case pasteMsg: m.insertRunesFromUserInput([]rune(msg)) @@ -851,8 +851,8 @@ func (m *Model) canAcceptSuggestion() bool { return len(m.matchedSuggestions) > 0 } -// updateSuggestions refreshes the list of matching suggestions. -func (m *Model) updateSuggestions() { +// UpdateSuggestions refreshes the list of matching suggestions. +func (m *Model) UpdateSuggestions() { if !m.ShowSuggestions { return } diff --git a/textinput/textinput_test.go b/textinput/textinput_test.go index 27a7640a..a7ee1582 100644 --- a/textinput/textinput_test.go +++ b/textinput/textinput_test.go @@ -22,7 +22,7 @@ func Test_CurrentSuggestion(t *testing.T) { } textinput.SetValue("test") - textinput.updateSuggestions() + textinput.UpdateSuggestions() textinput.nextSuggestion() suggestion = textinput.CurrentSuggestion() expected = "test2"