mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Merge pull request #694 from peco/fix-setdirty-add-pattern
Extract selectLine helper for SetDirty+Add pattern
This commit is contained in:
commit
dfbae22734
16
action.go
16
action.go
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue