Add bindable double-click event (#374)

This commit is contained in:
Junegunn Choi 2015-10-13 02:24:38 +09:00
parent b4ce89bbf5
commit f80ff8c917
3 changed files with 195 additions and 184 deletions

View File

@ -50,6 +50,7 @@ const (
Invalid
Mouse
DoubleClick
BTab
BSpace

View File

@ -343,6 +343,8 @@ func parseKeyChords(str string, message string) map[int]string {
chord = curses.SLeft
case "shift-right":
chord = curses.SRight
case "double-click":
chord = curses.DoubleClick
default:
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
chord = curses.CtrlA + int(lkey[5]) - 'a'

View File

@ -180,6 +180,7 @@ func defaultKeymap() map[int]actionType {
keymap[C.Rune] = actRune
keymap[C.Mouse] = actMouse
keymap[C.DoubleClick] = actAccept
return keymap
}
@ -858,6 +859,8 @@ func (t *Terminal) Loop() {
action = act
}
}
var doAction func(actionType) bool
doAction = func(action actionType) bool {
switch action {
case actIgnore:
case actExecute:
@ -867,12 +870,12 @@ func (t *Terminal) Loop() {
}
case actInvalid:
t.mutex.Unlock()
continue
return false
case actToggleSort:
t.sort = !t.sort
t.eventBox.Set(EvtSearchNew, t.sort)
t.mutex.Unlock()
continue
return false
case actBeginningOfLine:
t.cx = 0
case actBackwardChar:
@ -1040,7 +1043,7 @@ func (t *Terminal) Loop() {
// Double-click
if my >= min {
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
req(reqClose)
return doAction(t.keymap[C.DoubleClick])
}
}
} else if me.Down {
@ -1057,6 +1060,11 @@ func (t *Terminal) Loop() {
}
}
}
return true
}
if !doAction(action) {
continue
}
changed := string(previousInput) != string(t.input)
t.mutex.Unlock() // Must be unlocked before touching reqBox