SpawnMultiCursor creates a new multiple cursor at the next occurrence of the current selection or current word
()
| 2122 | |
| 2123 | // SpawnMultiCursor creates a new multiple cursor at the next occurrence of the current selection or current word |
| 2124 | func (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 |
| 2165 | func (h *BufPane) SpawnCursorAtLoc(loc buffer.Loc) *buffer.Cursor { |
nothing calls this directly
no test coverage detected