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

Method SpawnMultiCursor

internal/action/actions.go:2124–2162  ·  view source on GitHub ↗

SpawnMultiCursor creates a new multiple cursor at the next occurrence of the current selection or current word

()

Source from the content-addressed store, hash-verified

2122
2123// SpawnMultiCursor creates a new multiple cursor at the next occurrence of the current selection or current word
2124func (h *BufPane) SpawnMultiCursor() bool {
2125 spawner := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
2126 if !spawner.HasSelection() {
2127 spawner.SelectWord()
2128 h.multiWord = true
2129 h.Relocate()
2130 return true
2131 }
2132
2133 sel := spawner.GetSelection()
2134 searchStart := spawner.CurSelection[1]
2135
2136 search := string(sel)
2137 search = regexp.QuoteMeta(search)
2138 if h.multiWord {
2139 search = "\\b" + search + "\\b"
2140 }
2141 match, found, err := h.Buf.FindNext(search, h.Buf.Start(), h.Buf.End(), searchStart, true, true)
2142 if err != nil {
2143 InfoBar.Error(err)
2144 }
2145 if found {
2146 c := buffer.NewCursor(h.Buf, buffer.Loc{})
2147 c.SetSelectionStart(match[0])
2148 c.SetSelectionEnd(match[1])
2149 c.OrigSelection[0] = c.CurSelection[0]
2150 c.OrigSelection[1] = c.CurSelection[1]
2151 c.Loc = c.CurSelection[1]
2152
2153 h.Buf.AddCursor(c)
2154 h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
2155 h.Buf.MergeCursors()
2156 } else {
2157 InfoBar.Message("No matches found")
2158 }
2159
2160 h.Relocate()
2161 return true
2162}
2163
2164// SpawnCursorAtLoc spawns a new cursor at a location and merges the cursors
2165func (h *BufPane) SpawnCursorAtLoc(loc buffer.Loc) *buffer.Cursor {

Callers

nothing calls this directly

Calls 15

SetSelectionStartMethod · 0.95
SetSelectionEndMethod · 0.95
NewCursorFunction · 0.92
GetCursorMethod · 0.80
NumCursorsMethod · 0.80
SelectWordMethod · 0.80
AddCursorMethod · 0.80
SetCurCursorMethod · 0.80
MergeCursorsMethod · 0.80
RelocateMethod · 0.65
MessageMethod · 0.65
HasSelectionMethod · 0.45

Tested by

no test coverage detected