MCPcopy
hub / github.com/micro-editor/micro / MousePress

Method MousePress

internal/action/actions.go:59–109  ·  view source on GitHub ↗

MousePress is the event that should happen when a normal click happens This is almost always bound to left click

(e *tcell.EventMouse)

Source from the content-addressed store, hash-verified

57// MousePress is the event that should happen when a normal click happens
58// This is almost always bound to left click
59func (h *BufPane) MousePress(e *tcell.EventMouse) bool {
60 b := h.Buf
61 mx, my := e.Position()
62 // ignore click on the status line
63 if my >= h.BufView().Y+h.BufView().Height {
64 return false
65 }
66 mouseLoc := h.LocFromVisual(buffer.Loc{mx, my})
67 h.Cursor.Loc = mouseLoc
68
69 if b.NumCursors() > 1 {
70 b.ClearCursors()
71 h.Relocate()
72 h.Cursor = h.Buf.GetActiveCursor()
73 h.Cursor.Loc = mouseLoc
74 }
75 if time.Since(h.lastClickTime)/time.Millisecond < config.DoubleClickThreshold && (mouseLoc.X == h.lastLoc.X && mouseLoc.Y == h.lastLoc.Y) {
76 if h.DoubleClick {
77 // Triple click
78 h.lastClickTime = time.Now()
79
80 h.TripleClick = true
81 h.DoubleClick = false
82
83 h.Cursor.SelectLine()
84 h.Cursor.CopySelection(clipboard.PrimaryReg)
85 } else {
86 // Double click
87 h.lastClickTime = time.Now()
88
89 h.DoubleClick = true
90 h.TripleClick = false
91
92 h.Cursor.SelectWord()
93 h.Cursor.CopySelection(clipboard.PrimaryReg)
94 }
95 } else {
96 h.DoubleClick = false
97 h.TripleClick = false
98 h.lastClickTime = time.Now()
99
100 h.Cursor.OrigSelection[0] = h.Cursor.Loc
101 h.Cursor.CurSelection[0] = h.Cursor.Loc
102 h.Cursor.CurSelection[1] = h.Cursor.Loc
103 }
104
105 h.Cursor.StoreVisualX()
106 h.lastLoc = mouseLoc
107 h.Relocate()
108 return true
109}
110
111func (h *BufPane) MouseDrag(e *tcell.EventMouse) bool {
112 mx, my := e.Position()

Callers

nothing calls this directly

Calls 10

NumCursorsMethod · 0.80
ClearCursorsMethod · 0.80
GetActiveCursorMethod · 0.80
CopySelectionMethod · 0.80
SelectWordMethod · 0.80
StoreVisualXMethod · 0.80
BufViewMethod · 0.65
LocFromVisualMethod · 0.65
RelocateMethod · 0.65
SelectLineMethod · 0.45

Tested by

no test coverage detected