Skip to content

Commit

Permalink
Fix the wrong/redundant icon in the prompt bar (derailed#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjiec authored May 28, 2023
1 parent e6ff1a5 commit e928d93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
28 changes: 8 additions & 20 deletions internal/model/cmd_buff.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (
type CmdBuff struct {
buff []rune
suggestion string
listeners []BuffWatcher
listeners map[BuffWatcher]struct{}
hotKey rune
kind BufferKind
active bool
Expand All @@ -52,7 +52,7 @@ func NewCmdBuff(key rune, kind BufferKind) *CmdBuff {
hotKey: key,
kind: kind,
buff: make([]rune, 0, maxBuff),
listeners: []BuffWatcher{},
listeners: make(map[BuffWatcher]struct{}),
}
}

Expand Down Expand Up @@ -221,44 +221,32 @@ func (c *CmdBuff) Empty() bool {
func (c *CmdBuff) AddListener(w BuffWatcher) {
c.mx.Lock()
{
c.listeners = append(c.listeners, w)
c.listeners[w] = struct{}{}
}
c.mx.Unlock()
}

// RemoveListener removes a listener.
func (c *CmdBuff) RemoveListener(l BuffWatcher) {
c.mx.Lock()
defer c.mx.Unlock()

victim := -1
for i, lis := range c.listeners {
if l == lis {
victim = i
break
}
}
if victim == -1 {
return
}

c.listeners = append(c.listeners[:victim], c.listeners[victim+1:]...)
delete(c.listeners, l)
c.mx.Unlock()
}

func (c *CmdBuff) fireBufferCompleted(t, s string) {
for _, l := range c.listeners {
for l := range c.listeners {
l.BufferCompleted(t, s)
}
}

func (c *CmdBuff) fireBufferChanged(t, s string) {
for _, l := range c.listeners {
for l := range c.listeners {
l.BufferChanged(t, s)
}
}

func (c *CmdBuff) fireActive(b bool) {
for _, l := range c.listeners {
for l := range c.listeners {
l.BufferActive(b, c.GetKind())
}
}
1 change: 1 addition & 0 deletions internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (p *Prompt) InCmdMode() bool {
}

func (p *Prompt) activate() {
p.Clear()
p.SetCursorIndex(len(p.model.GetText()))
p.write(p.model.GetText(), p.model.GetSuggestion())
p.model.Notify(false)
Expand Down

0 comments on commit e928d93

Please sign in to comment.