Clicks with different x coordinates shouldn't be seen as a double-click
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 3761dc0 · Browse files · 3 files·+28 added−46 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+28 added−46 removed
- other:+28 added−46 removed
Provenance
- Commit
a893fc0- Tree
5d8511b- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
3761dc0
3 files changed+28 added−46 removed
modified:src/tui/light.go+5 added-5 removed
70 unmodified lines71 mouse bool72 forceBlack bool73 clearOnExit bool74 prevDownTime time.Time75- clickY []int75+ clicks [][2]int76 ttyin *os.File77 buffer []byte78 origState *term.State79 width int499 unmodified lines579 double := false580 if down && !drag {581 now := time.Now()582 if !left { // Right double click is not allowed583- r.clickY = []int{}583+ r.clicks = [][2]int{}584 } else if now.Sub(r.prevDownTime) < doubleClickDuration {585- r.clickY = append(r.clickY, y)585+ r.clicks = append(r.clicks, [2]int{x, y})586 } else {587- r.clickY = []int{y}587+ r.clicks = [][2]int{{x, y}}588 }589 r.prevDownTime = now590 } else {591- if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] &&591+ if len(r.clicks) > 1 && r.clicks[0][0] == r.clicks[1][0] && r.clicks[0][1] == r.clicks[1][1] &&592 time.Since(r.prevDownTime) < doubleClickDuration {593 double = true594 }595 }436 unmodified linesmodified:src/tui/tcell.go+21 added-39 removed
4 unmodified lines5 import (6 "os"7 "time"8 9- "runtime"10-9 "github.com/gdamore/tcell/v2"10 "github.com/gdamore/tcell/v2/encoding"11 12 "github.com/mattn/go-runewidth"202 unmodified lines215 case button&tcell.WheelDown != 0:216 return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}217 case button&tcell.WheelUp != 0:218 return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}219+ case button&tcell.Button1 != 0:220+ double := false221- case button&tcell.Button1 != 0 && !drag:222- // all potential double click events put their 'line' coordinate in the clickY array223- // double click event has two conditions, temporal and spatial, the first is checked here224- now := time.Now()225- if now.Sub(r.prevDownTime) < doubleClickDuration {226- r.clickY = append(r.clickY, y)227- } else {228- r.clickY = []int{y}229- }230- r.prevDownTime = now221+ if !drag {222+ // all potential double click events put their coordinates in the clicks array223+ // double click event has two conditions, temporal and spatial, the first is checked here224+ now := time.Now()225+ if now.Sub(r.prevDownTime) < doubleClickDuration {226+ r.clicks = append(r.clicks, [2]int{x, y})227+ } else {228+ r.clicks = [][2]int{{x, y}}229+ }230+ r.prevDownTime = now231 232- // detect double clicks (also check for spatial condition)233- n := len(r.clickY)234- double := n > 1 && r.clickY[n-2] == r.clickY[n-1]235- if double {236- // make sure two consecutive double clicks require four clicks237- r.clickY = []int{}232+ // detect double clicks (also check for spatial condition)233+ n := len(r.clicks)234+ double = n > 1 && r.clicks[n-2][0] == r.clicks[n-1][0] && r.clicks[n-2][1] == r.clicks[n-1][1]235+ if double {236+ // make sure two consecutive double clicks require four clicks237+ r.clicks = [][2]int{}238+ }239 }239-240 // fire single or double click event241 return Event{Mouse, 0, &MouseEvent{y, x, 0, true, !double, double, mod}}242- case button&tcell.Button2 != 0 && !drag:242+ case button&tcell.Button2 != 0:243 return Event{Mouse, 0, &MouseEvent{y, x, 0, false, true, false, mod}}244- case runtime.GOOS != "windows":245-244+ default:245 // double and single taps on Windows don't quite work due to246 // the console acting on the events and not allowing us247 // to consume them.249-248 left := button&tcell.Button1 != 0249 down := left || button&tcell.Button3 != 0250 double := false253- if down {254- now := time.Now()255- if !left {256- r.clickY = []int{}257- } else if now.Sub(r.prevDownTime) < doubleClickDuration {258- r.clickY = append(r.clickY, x)259- } else {260- r.clickY = []int{x}261- r.prevDownTime = now262- }263- } else {264- if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] &&265- time.Now().Sub(r.prevDownTime) < doubleClickDuration {266- double = true267- }268- }251 252 return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}253 }254 466 unmodified linesmodified:src/tui/tui.go+2 added-2 removed
429 unmodified lines430 theme *ColorTheme431 mouse bool432 forceBlack bool433 prevDownTime time.Time434- clickY []int434+ clicks [][2]int435 }436 437 func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {438 r := &FullscreenRenderer{439 theme: theme,440 mouse: mouse,441 forceBlack: forceBlack,442 prevDownTime: time.Unix(0, 0),443- clickY: []int{}}443+ clicks: [][2]int{}}444 return r445 }446 447 var (247 unmodified lines