Add bindable double-click event (#374)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent b4ce89b · Browse files · 3 files·+192 added−181 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+192 added−181 removed
- other:+192 added−181 removed
Provenance
- Commit
f80ff8c- Tree
b943aa4- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
b4ce89b
3 files changed+192 added−181 removed
modified:src/curses/curses.go+1 added
48 unmodified lines49 ESC50 51 Invalid52 Mouse53+ DoubleClick54 55 BTab56 BSpace57 492 unmodified linesmodified:src/options.go+2 added
341 unmodified lines342 case "shift-left":343 chord = curses.SLeft344 case "shift-right":345 chord = curses.SRight346+ case "double-click":347+ chord = curses.DoubleClick348 default:349 if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {350 chord = curses.CtrlA + int(lkey[5]) - 'a'351 } else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {546 unmodified linesmodified:src/terminal.go+189 added-181 removed
178 unmodified lines179 keymap[C.PgDn] = actPageDown180 181 keymap[C.Rune] = actRune182 keymap[C.Mouse] = actMouse183+ keymap[C.DoubleClick] = actAccept184 return keymap185 }186 187 // NewTerminal returns new Terminal object670 unmodified lines858 if act, prs := t.keymap[mapkey]; prs {859 action = act860 }861 }861- switch action {862- case actIgnore:863- case actExecute:864- if t.cy >= 0 && t.cy < t.merger.Length() {865- item := t.merger.Get(t.cy)866- executeCommand(t.execmap[mapkey], item.AsString(t.ansi))867- }868- case actInvalid:869- t.mutex.Unlock()870- continue871- case actToggleSort:872- t.sort = !t.sort873- t.eventBox.Set(EvtSearchNew, t.sort)874- t.mutex.Unlock()875- continue876- case actBeginningOfLine:877- t.cx = 0878- case actBackwardChar:879- if t.cx > 0 {880- t.cx--881- }882- case actAbort:883- req(reqQuit)884- case actDeleteChar:885- t.delChar()886- case actDeleteCharEOF:887- if !t.delChar() && t.cx == 0 {888- req(reqQuit)889- }890- case actEndOfLine:891- t.cx = len(t.input)892- case actCancel:893- if len(t.input) == 0 {894- req(reqQuit)895- } else {896- t.yanked = t.input897- t.input = []rune{}862+ var doAction func(actionType) bool863+ doAction = func(action actionType) bool {864+ switch action {865+ case actIgnore:866+ case actExecute:867+ if t.cy >= 0 && t.cy < t.merger.Length() {868+ item := t.merger.Get(t.cy)869+ executeCommand(t.execmap[mapkey], item.AsString(t.ansi))870+ }871+ case actInvalid:872+ t.mutex.Unlock()873+ return false874+ case actToggleSort:875+ t.sort = !t.sort876+ t.eventBox.Set(EvtSearchNew, t.sort)877+ t.mutex.Unlock()878+ return false879+ case actBeginningOfLine:880 t.cx = 0899- }900- case actForwardChar:901- if t.cx < len(t.input) {902- t.cx++881+ case actBackwardChar:882+ if t.cx > 0 {883+ t.cx--903- }904- case actBackwardDeleteChar:905- if t.cx > 0 {906- t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)907- t.cx--908- }909- case actSelectAll:910- if t.multi {911- for i := 0; i < t.merger.Length(); i++ {912- item := t.merger.Get(i)913- selectItem(item)884 }915- req(reqList, reqInfo)916- }917- case actDeselectAll:918- if t.multi {919- for i := 0; i < t.merger.Length(); i++ {920- item := t.merger.Get(i)921- delete(t.selected, item.index)885+ case actAbort:886+ req(reqQuit)887+ case actDeleteChar:888+ t.delChar()889+ case actDeleteCharEOF:890+ if !t.delChar() && t.cx == 0 {891+ req(reqQuit)892 }923- req(reqList, reqInfo)924- }925- case actToggle:926- if t.multi && t.merger.Length() > 0 {927- toggle()928- req(reqList)929- }930- case actToggleAll:931- if t.multi {932- for i := 0; i < t.merger.Length(); i++ {933- toggleY(i)893+ case actEndOfLine:894+ t.cx = len(t.input)895+ case actCancel:896+ if len(t.input) == 0 {897+ req(reqQuit)898+ } else {899+ t.yanked = t.input900+ t.input = []rune{}901+ t.cx = 0902 }903+ case actForwardChar:904+ if t.cx < len(t.input) {905+ t.cx++906+ }907+ case actBackwardDeleteChar:908+ if t.cx > 0 {909+ t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)910+ t.cx--911+ }912+ case actSelectAll:913+ if t.multi {914+ for i := 0; i < t.merger.Length(); i++ {915+ item := t.merger.Get(i)916+ selectItem(item)917+ }918+ req(reqList, reqInfo)919+ }920+ case actDeselectAll:921+ if t.multi {922+ for i := 0; i < t.merger.Length(); i++ {923+ item := t.merger.Get(i)924+ delete(t.selected, item.index)925+ }926+ req(reqList, reqInfo)927+ }928+ case actToggle:929+ if t.multi && t.merger.Length() > 0 {930+ toggle()931+ req(reqList)932+ }933+ case actToggleAll:934+ if t.multi {935+ for i := 0; i < t.merger.Length(); i++ {936+ toggleY(i)937+ }935- req(reqList, reqInfo)936- }937- case actToggleDown:938- if t.multi && t.merger.Length() > 0 {939- toggle()938+ req(reqList, reqInfo)939+ }940+ case actToggleDown:941+ if t.multi && t.merger.Length() > 0 {942+ toggle()943+ t.vmove(-1)944+ req(reqList)945+ }946+ case actToggleUp:947+ if t.multi && t.merger.Length() > 0 {948+ toggle()949+ t.vmove(1)950+ req(reqList)951+ }952+ case actDown:953 t.vmove(-1)954 req(reqList)942- }943- case actToggleUp:955+ case actUp:944- if t.multi && t.merger.Length() > 0 {945- toggle()956 t.vmove(1)957 req(reqList)948- }949- case actDown:950- t.vmove(-1)951- req(reqList)952- case actUp:953- t.vmove(1)954- req(reqList)955- case actAccept:956- req(reqClose)957- case actClearScreen:958- req(reqRedraw)959- case actUnixLineDiscard:960- if t.cx > 0 {961- t.yanked = copySlice(t.input[:t.cx])962- t.input = t.input[t.cx:]963- t.cx = 0958+ case actAccept:959+ req(reqClose)960+ case actClearScreen:961+ req(reqRedraw)962+ case actUnixLineDiscard:963+ if t.cx > 0 {964+ t.yanked = copySlice(t.input[:t.cx])965+ t.input = t.input[t.cx:]966+ t.cx = 0964- }965- case actUnixWordRubout:966- if t.cx > 0 {967- t.rubout("\\s\\S")968- }969- case actBackwardKillWord:970- if t.cx > 0 {971- t.rubout("[^[:alnum:]][[:alnum:]]")972- }973- case actYank:974- suffix := copySlice(t.input[t.cx:])975- t.input = append(append(t.input[:t.cx], t.yanked...), suffix...)976- t.cx += len(t.yanked)977- case actPageUp:978- t.vmove(t.maxItems() - 1)979- req(reqList)980- case actPageDown:981- t.vmove(-(t.maxItems() - 1))982- req(reqList)983- case actBackwardWord:984- t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1985- case actForwardWord:986- t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1987- case actKillWord:988- ncx := t.cx +989- findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1990- if ncx > t.cx {991- t.yanked = copySlice(t.input[t.cx:ncx])992- t.input = append(t.input[:t.cx], t.input[ncx:]...)993- }994- case actKillLine:995- if t.cx < len(t.input) {996- t.yanked = copySlice(t.input[t.cx:])997- t.input = t.input[:t.cx]998- }999- case actRune:1000- prefix := copySlice(t.input[:t.cx])1001- t.input = append(append(prefix, event.Char), t.input[t.cx:]...)1002- t.cx++1003- case actPreviousHistory:1004- if t.history != nil {1005- t.history.override(string(t.input))1006- t.input = []rune(t.history.previous())1007- t.cx = len(t.input)1008- }1009- case actNextHistory:1010- if t.history != nil {1011- t.history.override(string(t.input))1012- t.input = []rune(t.history.next())1013- t.cx = len(t.input)1014- }1015- case actMouse:1016- me := event.MouseEvent1017- mx, my := me.X, me.Y1018- if me.S != 0 {1019- // Scroll1020- if t.merger.Length() > 0 {1021- if t.multi && me.Mod {1022- toggle()1023- }1024- t.vmove(me.S)1025- req(reqList)967 }1027- } else if mx >= t.marginInt[3] && mx < C.MaxX()-t.marginInt[1] &&1028- my >= t.marginInt[0] && my < C.MaxY()-t.marginInt[2] {1029- mx -= t.marginInt[3]1030- my -= t.marginInt[0]1031- mx = util.Constrain(mx-len(t.prompt), 0, len(t.input))1032- if !t.reverse {1033- my = t.maxHeight() - my - 1968+ case actUnixWordRubout:969+ if t.cx > 0 {970+ t.rubout("\\s\\S")971 }1035- min := 2 + len(t.header)1036- if t.inlineInfo {1037- min--972+ case actBackwardKillWord:973+ if t.cx > 0 {974+ t.rubout("[^[:alnum:]][[:alnum:]]")975 }1039- if me.Double {1040- // Double-click1041- if my >= min {1042- if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {1043- req(reqClose)1044- }1045- }1046- } else if me.Down {1047- if my == 0 && mx >= 0 {1048- // Prompt1049- t.cx = mx1050- } else if my >= min {1051- // List1052- if t.vset(t.offset+my-min) && t.multi && me.Mod {976+ case actYank:977+ suffix := copySlice(t.input[t.cx:])978+ t.input = append(append(t.input[:t.cx], t.yanked...), suffix...)979+ t.cx += len(t.yanked)980+ case actPageUp:981+ t.vmove(t.maxItems() - 1)982+ req(reqList)983+ case actPageDown:984+ t.vmove(-(t.maxItems() - 1))985+ req(reqList)986+ case actBackwardWord:987+ t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1988+ case actForwardWord:989+ t.cx += findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1990+ case actKillWord:991+ ncx := t.cx +992+ findFirstMatch("[[:alnum:]][^[:alnum:]]|(.$)", string(t.input[t.cx:])) + 1993+ if ncx > t.cx {994+ t.yanked = copySlice(t.input[t.cx:ncx])995+ t.input = append(t.input[:t.cx], t.input[ncx:]...)996+ }997+ case actKillLine:998+ if t.cx < len(t.input) {999+ t.yanked = copySlice(t.input[t.cx:])1000+ t.input = t.input[:t.cx]1001+ }1002+ case actRune:1003+ prefix := copySlice(t.input[:t.cx])1004+ t.input = append(append(prefix, event.Char), t.input[t.cx:]...)1005+ t.cx++1006+ case actPreviousHistory:1007+ if t.history != nil {1008+ t.history.override(string(t.input))1009+ t.input = []rune(t.history.previous())1010+ t.cx = len(t.input)1011+ }1012+ case actNextHistory:1013+ if t.history != nil {1014+ t.history.override(string(t.input))1015+ t.input = []rune(t.history.next())1016+ t.cx = len(t.input)1017+ }1018+ case actMouse:1019+ me := event.MouseEvent1020+ mx, my := me.X, me.Y1021+ if me.S != 0 {1022+ // Scroll1023+ if t.merger.Length() > 0 {1024+ if t.multi && me.Mod {1025 toggle()1026 }1027+ t.vmove(me.S)1028 req(reqList)1029 }1030+ } else if mx >= t.marginInt[3] && mx < C.MaxX()-t.marginInt[1] &&1031+ my >= t.marginInt[0] && my < C.MaxY()-t.marginInt[2] {1032+ mx -= t.marginInt[3]1033+ my -= t.marginInt[0]1034+ mx = util.Constrain(mx-len(t.prompt), 0, len(t.input))1035+ if !t.reverse {1036+ my = t.maxHeight() - my - 11037+ }1038+ min := 2 + len(t.header)1039+ if t.inlineInfo {1040+ min--1041+ }1042+ if me.Double {1043+ // Double-click1044+ if my >= min {1045+ if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {1046+ return doAction(t.keymap[C.DoubleClick])1047+ }1048+ }1049+ } else if me.Down {1050+ if my == 0 && mx >= 0 {1051+ // Prompt1052+ t.cx = mx1053+ } else if my >= min {1054+ // List1055+ if t.vset(t.offset+my-min) && t.multi && me.Mod {1056+ toggle()1057+ }1058+ req(reqList)1059+ }1060+ }1061 }1062 }1063+ return true1064 }1065+ if !doAction(action) {1066+ continue1067+ }1068 changed := string(previousInput) != string(t.input)1069 t.mutex.Unlock() // Must be unlocked before touching reqBox1070 1071 if changed {63 unmodified lines