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 Invalid
Mouse Mouse
DoubleClick
BTab BTab
BSpace BSpace

View File

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

View File

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