1515)
1616
1717type model struct {
18- fzf * FZF
19- items * items
18+ fzf * FZF
19+ items * items
20+ findOption * findOption
2021
2122 // state
2223 abort bool
@@ -46,7 +47,7 @@ type model struct {
4647 input textinput.Model
4748}
4849
49- func newModel (fzf * FZF , items * items ) * model {
50+ func newModel (fzf * FZF , items * items , opt * findOption ) * model {
5051 input := textinput .New ()
5152 input .Prompt = fzf .option .prompt
5253 input .Placeholder = fzf .option .inputPlaceholder
@@ -56,9 +57,18 @@ func newModel(fzf *FZF, items *items) *model {
5657 fzf .option .keymap .Toggle .SetEnabled (false )
5758 }
5859
60+ var matches fuzzy.Matches
61+ for i := 0 ; i < items .Len (); i ++ {
62+ matches = append (matches , fuzzy.Match {
63+ Str : items .String (i ),
64+ Index : i ,
65+ })
66+ }
67+
5968 return & model {
60- fzf : fzf ,
61- items : items ,
69+ fzf : fzf ,
70+ items : items ,
71+ findOption : opt ,
6272 // state
6373 abort : false ,
6474
@@ -75,7 +85,7 @@ func newModel(fzf *FZF, items *items) *model {
7585 cursorLineStyle : fzf .option .styles .option .cursorLine ,
7686 cursorLineMatchesStyle : lipgloss .NewStyle ().Inherit (fzf .option .styles .option .matches ).Inherit (fzf .option .styles .option .cursorLine ),
7787
78- matches : fuzzy. Matches {} ,
88+ matches : matches ,
7989 choices : []int {},
8090 // window
8191 windowWidth : 0 ,
@@ -150,8 +160,8 @@ func (m *model) itemsView() string {
150160 }
151161
152162 // write item prefix
153- if m .items . HasItemPrefixFunc () {
154- _ , _ = v .WriteString (stringLinesToSpace (m .items .itemPrefixFunc (match .Index )))
163+ if m .findOption . itemPrefixFunc != nil {
164+ _ , _ = v .WriteString (stringLinesToSpace (m .findOption .itemPrefixFunc (match .Index )))
155165 }
156166
157167 // write item
@@ -170,7 +180,7 @@ func (m *model) itemsView() string {
170180 }
171181 }
172182
173- if i + 1 = = m .windowHeight - headerHeight {
183+ if i + 1 > = m .windowHeight - headerHeight {
174184 break
175185 }
176186 v .WriteString ("\n " )
@@ -202,27 +212,35 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
202212 case key .Matches (msg , m .fzf .option .keymap .Up ):
203213 // up
204214 m .cursorUp ()
215+ m .fixYPosition ()
216+ m .fixCursor ()
205217 case key .Matches (msg , m .fzf .option .keymap .Down ):
206218 // down
207219 m .cursorDown ()
220+ m .fixYPosition ()
221+ m .fixCursor ()
208222 }
209223 case tea.WindowSizeMsg :
210224 // window
211225 m .windowWidth = msg .Width
212226 m .windowHeight = msg .Height
213227 m .input .Width = m .windowWidth - m .promptWidth
228+ m .fixYPosition ()
229+ m .fixCursor ()
214230 }
215231
216232 var cmds []tea.Cmd
233+ beforeValue := m .input .Value ()
217234 {
218235 input , cmd := m .input .Update (msg )
219236 m .input = input
220237 cmds = append (cmds , cmd )
221238 }
222-
223- m .filter ()
224- m .fixYPosition ()
225- m .fixCursor ()
239+ if beforeValue != m .input .Value () {
240+ m .filter ()
241+ m .fixYPosition ()
242+ m .fixCursor ()
243+ }
226244
227245 return m , tea .Batch (cmds ... )
228246}
@@ -267,10 +285,9 @@ func (m *model) cursorDown() {
267285}
268286
269287func (m * model ) filter () {
270- var matches fuzzy.Matches
271-
272288 s := m .input .Value ()
273289 if s == "" {
290+ var matches fuzzy.Matches
274291 for i := 0 ; i < m .items .Len (); i ++ {
275292 matches = append (matches , fuzzy.Match {
276293 Str : m .items .String (i ),
0 commit comments