From 7b706bb9c3d01f9941880876f41605d26dfdc153 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Thu, 9 Nov 2023 05:58:12 -0500 Subject: [PATCH] fix: several bugs --- pkg/fuzzy/module.go | 2 +- pkg/util/pubsub.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/fuzzy/module.go b/pkg/fuzzy/module.go index 7976febe..916c7a43 100644 --- a/pkg/fuzzy/module.go +++ b/pkg/fuzzy/module.go @@ -158,7 +158,7 @@ func (f *Fuzzy) Update(msg tea.Msg) (taro.Model, tea.Cmd) { f.selected = geom.Clamp(f.selected+delta, 0, len(f.getOptions())-1) return f, f.handlePreview() case taro.KeyEnter: - if f.selected < len(f.getOptions()) { + if f.selected >= 0 && f.selected < len(f.getOptions()) { option := f.getOptions()[f.selected] f.result <- option.Result } else { diff --git a/pkg/util/pubsub.go b/pkg/util/pubsub.go index c926a405..12bbf622 100644 --- a/pkg/util/pubsub.go +++ b/pkg/util/pubsub.go @@ -18,11 +18,14 @@ func NewPublisher[T any]() *Publisher[T] { } func (p *Publisher[T]) Publish(value T) { + subscribers := make([]*Subscriber[T], 0) p.m.Lock() - subscribers := p.subscribers + for subscriber := range p.subscribers { + subscribers = append(subscribers, subscriber) + } p.m.Unlock() - for subscriber := range subscribers { + for _, subscriber := range subscribers { subscriber.m.RLock() active := subscriber.active subscriber.m.RUnlock()