Merge pull request #694 from peco/fix-setdirty-add-pattern

Extract selectLine helper for SetDirty+Add pattern
This commit is contained in:
lestrrat 2026-02-18 14:48:09 +09:00 committed by GitHub
commit dfbae22734
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,6 +180,12 @@ func init() {
)
}
// selectLine marks the line as dirty and adds it to the selection.
func selectLine(l line.Line, s *Selection) {
l.SetDirty(true)
s.Add(l)
}
// This is a noop action
func doNothing(_ context.Context, _ *Peco, _ Event) {}
@ -290,8 +296,7 @@ func doSelectAll(ctx context.Context, state *Peco, _ Event) {
if err != nil {
continue
}
l.SetDirty(true)
selection.Add(l)
selectLine(l, selection)
}
state.Hub().SendDraw(ctx, nil)
}
@ -312,8 +317,7 @@ func doSelectVisible(ctx context.Context, state *Peco, _ Event) {
if err != nil {
continue
}
l.SetDirty(true)
selection.Add(l)
selectLine(l, selection)
}
state.Hub().SendDraw(ctx, nil)
}
@ -453,11 +457,11 @@ func doInvertSelection(ctx context.Context, state *Peco, _ Event) {
if err != nil {
continue
}
l.SetDirty(true)
if selection.Has(l) {
l.SetDirty(true)
selection.Remove(l)
} else {
selection.Add(l)
selectLine(l, selection)
}
}