+// SpawnMultiCursor creates a new multiple cursor at the next occurence of the current selection or current word
+func (v *View) SpawnMultiCursor(usePlugin bool) bool {
+ spawner := v.Buf.cursors[len(v.Buf.cursors)-1]
+ // You can only spawn a cursor from the main cursor
+ if v.Cursor == spawner {
+ if usePlugin && !PreActionCall("SpawnMultiCursor", v) {
+ return false
+ }
+
+ if !spawner.HasSelection() {
+ spawner.SelectWord()
+ } else {
+ c := &Cursor{
+ buf: v.Buf,
+ }
+
+ sel := spawner.GetSelection()
+
+ searchStart = ToCharPos(spawner.CurSelection[1], v.Buf)
+ v.Cursor = c
+ Search(sel, v, true)
+
+ for _, cur := range v.Buf.cursors {
+ if c.Loc == cur.Loc {
+ return false
+ }
+ }
+ v.Buf.cursors = append(v.Buf.cursors, c)
+ v.Buf.UpdateCursors()
+ v.Relocate()
+ v.Cursor = spawner
+ }
+
+ if usePlugin {
+ PostActionCall("SpawnMultiCursor", v)
+ }
+ }
+
+ 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)
+ v.Buf.UpdateCursors()
+
+ 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]
+
+ if v.Cursor == cursor {
+ if usePlugin && !PreActionCall("SkipMultiCursor", v) {
+ return false
+ }
+ sel := cursor.GetSelection()
+
+ searchStart = ToCharPos(cursor.CurSelection[1], v.Buf)
+ v.Cursor = cursor
+ Search(sel, v, true)
+ v.Relocate()
+ v.Cursor = cursor
+
+ if usePlugin {
+ PostActionCall("SkipMultiCursor", v)
+ }
+ }
+ return false
+}
+
+// RemoveMultiCursor removes the latest multiple cursor
+func (v *View) RemoveMultiCursor(usePlugin bool) bool {
+ end := len(v.Buf.cursors)
+ if end > 1 {
+ lastOne := v.Buf.cursors[end-1]
+ if v.Cursor == lastOne {
+ if usePlugin && !PreActionCall("RemoveMultiCursor", v) {
+ return false
+ }
+
+ v.Buf.cursors[end-1] = nil
+ v.Buf.cursors = v.Buf.cursors[:end-1]
+ v.Buf.UpdateCursors()
+ v.Relocate()
+
+ if usePlugin {
+ return PostActionCall("RemoveMultiCursor", v)
+ }
+ return true
+ }
+ } else {
+ v.RemoveAllMultiCursors(usePlugin)
+ }
+ return false
+}
+
+// RemoveAllMultiCursors removes all cursors except the base cursor
+func (v *View) RemoveAllMultiCursors(usePlugin bool) bool {
+ if v.Cursor == v.Buf.cursors[len(v.Buf.cursors)-1] {
+ if usePlugin && !PreActionCall("RemoveAllMultiCursors", v) {
+ return false
+ }
+
+ for i := 1; i < len(v.Buf.cursors); i++ {
+ v.Buf.cursors[i] = nil
+ }
+ v.Buf.cursors = v.Buf.cursors[:1]
+ v.Buf.UpdateCursors()
+ v.Cursor.ResetSelection()
+ v.Relocate()
+
+ if usePlugin {
+ return PostActionCall("RemoveAllMultiCursors", v)
+ }
+ return true
+ }