From e5026ef3fae63d13d5e6612b244c030cf4f50a3a Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Mon, 4 Mar 2024 22:21:50 +0100 Subject: [PATCH] Make MouseMultiCursor toggle cursors (#3146) It is useful to be able to use mouse not only for adding new cursors but also for removing them. So let's modify MouseMultiCursor behavior: if a cursor already exists at the mouse click location, remove it. --- internal/action/actions.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index be197d74..bfbf2354 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1828,11 +1828,23 @@ func (h *BufPane) SpawnMultiCursorSelect() bool { return true } -// MouseMultiCursor is a mouse action which puts a new cursor at the mouse position +// MouseMultiCursor is a mouse action which puts a new cursor at the mouse position, +// or removes a cursor if it is already there func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool { b := h.Buf mx, my := e.Position() mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my}) + + if h.Buf.NumCursors() > 1 { + cursors := h.Buf.GetCursors() + for _, c := range cursors { + if c.Loc == mouseLoc { + h.Buf.RemoveCursor(c.Num) + return true + } + } + } + c := buffer.NewCursor(b, mouseLoc) b.AddCursor(c) b.MergeCursors()