Add ability to add cursors with Ctrl-MouseLeft
With the new code that allows binding mouse buttons this was remarkably easy to add. The new binding is: "Ctrl-MouseLeft": "MouseMultiCursor" Note: A number of terminals don't support Ctrl-MouseLeft (macOS especially) so you might want to rebind to MouseRight or MouseMiddle.
This commit is contained in:
parent
c3a73d63b8
commit
00718f99cf
3 changed files with 32 additions and 3 deletions
|
@ -1869,6 +1869,33 @@ func (v *View) SpawnMultiCursor(usePlugin bool) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// MouseMultiCursor is a mouse action which puts a new cursor at the mouse position
|
||||
func (v *View) MouseMultiCursor(usePlugin bool, e *tcell.EventMouse) bool {
|
||||
if v.Cursor == &v.Buf.Cursor {
|
||||
if usePlugin && !PreActionCall("SpawnMultiCursorAtMouse", v, e) {
|
||||
return false
|
||||
}
|
||||
x, y := e.Position()
|
||||
x -= v.lineNumOffset - v.leftCol + v.x
|
||||
y += v.Topline - v.y
|
||||
|
||||
c := &Cursor{
|
||||
buf: v.Buf,
|
||||
}
|
||||
v.Cursor = c
|
||||
v.MoveToMouseClick(x, y)
|
||||
v.Relocate()
|
||||
v.Cursor = &v.Buf.Cursor
|
||||
|
||||
v.Buf.cursors = append(v.Buf.cursors, c)
|
||||
|
||||
if usePlugin {
|
||||
PostActionCall("SpawnMultiCursorAtMouse", v)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SkipMultiCursor moves the current multiple cursor to the next available position
|
||||
func (v *View) SkipMultiCursor(usePlugin bool) bool {
|
||||
cursor := v.Buf.cursors[len(v.Buf.cursors)-1]
|
||||
|
|
|
@ -14,7 +14,8 @@ var mouseBindings map[Key][]func(*View, bool, *tcell.EventMouse) bool
|
|||
var helpBinding string
|
||||
|
||||
var mouseBindingActions = map[string]func(*View, bool, *tcell.EventMouse) bool{
|
||||
"MousePress": (*View).MousePress,
|
||||
"MousePress": (*View).MousePress,
|
||||
"MouseMultiCursor": (*View).MouseMultiCursor,
|
||||
}
|
||||
|
||||
var bindingActions = map[string]func(*View, bool) bool{
|
||||
|
@ -517,6 +518,7 @@ func DefaultBindings() map[string]string {
|
|||
"MouseWheelDown": "ScrollDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||
|
||||
"Alt-n": "SpawnMultiCursor",
|
||||
"Alt-p": "RemoveMultiCursor",
|
||||
|
|
|
@ -561,7 +561,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
|||
button := e.Buttons()
|
||||
|
||||
for key, actions := range bindings {
|
||||
if button == key.buttons {
|
||||
if button == key.buttons && e.Modifiers() == key.modifiers {
|
||||
for _, c := range v.Buf.cursors {
|
||||
v.Cursor = c
|
||||
relocate = v.ExecuteActions(actions) || relocate
|
||||
|
@ -571,7 +571,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
|||
}
|
||||
|
||||
for key, actions := range mouseBindings {
|
||||
if button == key.buttons {
|
||||
if button == key.buttons && e.Modifiers() == key.modifiers {
|
||||
for _, action := range actions {
|
||||
action(v, true, e)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue