Fix incorrect behaviors of mouse events when --multi enabled

This commit is contained in:
Junegunn Choi 2015-01-10 12:21:17 +09:00
parent 8b02ae650c
commit 188c90bf25

View File

@ -416,14 +416,6 @@ func (t *Terminal) Loop() {
t.mutex.Lock() t.mutex.Lock()
previousInput := t.input previousInput := t.input
events := []EventType{REQ_PROMPT} events := []EventType{REQ_PROMPT}
toggle := func() {
item := t.merger.Get(t.listIndex(t.cy))
if _, found := t.selected[item.text]; !found {
t.selected[item.text] = item.origText
} else {
delete(t.selected, item.text)
}
}
req := func(evts ...EventType) { req := func(evts ...EventType) {
for _, event := range evts { for _, event := range evts {
events = append(events, event) events = append(events, event)
@ -432,6 +424,18 @@ func (t *Terminal) Loop() {
} }
} }
} }
toggle := func() {
idx := t.listIndex(t.cy)
if idx < t.merger.Length() {
item := t.merger.Get(idx)
if _, found := t.selected[item.text]; !found {
t.selected[item.text] = item.origText
} else {
delete(t.selected, item.text)
}
req(REQ_INFO)
}
}
switch event.Type { switch event.Type {
case C.INVALID: case C.INVALID:
t.mutex.Unlock() t.mutex.Unlock()
@ -463,13 +467,13 @@ func (t *Terminal) Loop() {
if t.multi && t.merger.Length() > 0 { if t.multi && t.merger.Length() > 0 {
toggle() toggle()
t.vmove(-1) t.vmove(-1)
req(REQ_LIST, REQ_INFO) req(REQ_LIST)
} }
case C.BTAB: case C.BTAB:
if t.multi && t.merger.Length() > 0 { if t.multi && t.merger.Length() > 0 {
toggle() toggle()
t.vmove(1) t.vmove(1)
req(REQ_LIST, REQ_INFO) req(REQ_LIST)
} }
case C.CTRL_J, C.CTRL_N: case C.CTRL_J, C.CTRL_N:
t.vmove(-1) t.vmove(-1)
@ -529,11 +533,13 @@ func (t *Terminal) Loop() {
} }
if me.S != 0 { if me.S != 0 {
// Scroll // Scroll
if me.Mod { if t.merger.Length() > 0 {
toggle() if t.multi && me.Mod {
toggle()
}
t.vmove(me.S)
req(REQ_LIST)
} }
t.vmove(me.S)
req(REQ_LIST)
} else if me.Double { } else if me.Double {
// Double-click // Double-click
if my >= 2 { if my >= 2 {
@ -547,7 +553,7 @@ func (t *Terminal) Loop() {
} else if my >= 2 { } else if my >= 2 {
// List // List
t.cy = t.offset + my - 2 t.cy = t.offset + my - 2
if me.Mod { if t.multi && me.Mod {
toggle() toggle()
} }
req(REQ_LIST) req(REQ_LIST)