mirror of
https://github.com/Hopiu/micro.git
synced 2026-05-24 14:13:44 +00:00
Implement SpawnMultiCursorSelect (#1046)
Add function to actions.go which adds a new cursor to the beginning of each line of a selection. Bind to Ctrl-M by default.
This commit is contained in:
parent
3293160dcb
commit
ac0b89366b
3 changed files with 51 additions and 0 deletions
|
|
@ -2144,6 +2144,54 @@ func (v *View) SpawnMultiCursor(usePlugin bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SpawnMultiCursorSelect adds a cursor at the beginning of each line of a selection
|
||||||
|
func (v *View) SpawnMultiCursorSelect(usePlugin bool) bool {
|
||||||
|
if v.Cursor == &v.Buf.Cursor {
|
||||||
|
if usePlugin && !PreActionCall("SpawnMultiCursorSelect", v) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avoid cases where multiple cursors already exist, that would create problems
|
||||||
|
if len(v.Buf.cursors) > 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var startLine int
|
||||||
|
var endLine int
|
||||||
|
|
||||||
|
a, b := v.Cursor.CurSelection[0].Y, v.Cursor.CurSelection[1].Y
|
||||||
|
if a > b {
|
||||||
|
startLine, endLine = b, a
|
||||||
|
} else {
|
||||||
|
startLine, endLine = a, b
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Cursor.HasSelection() {
|
||||||
|
v.Cursor.ResetSelection()
|
||||||
|
v.Cursor.GotoLoc(Loc{0, startLine})
|
||||||
|
|
||||||
|
for i := startLine; i <= endLine; i++ {
|
||||||
|
c := &Cursor{
|
||||||
|
buf: v.Buf,
|
||||||
|
}
|
||||||
|
c.GotoLoc(Loc{0, i})
|
||||||
|
v.Buf.cursors = append(v.Buf.cursors, c)
|
||||||
|
}
|
||||||
|
v.Buf.MergeCursors()
|
||||||
|
v.Buf.UpdateCursors()
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if usePlugin {
|
||||||
|
PostActionCall("SpawnMultiCursorSelect", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
messenger.Message("Added cursors from selection")
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
func (v *View) MouseMultiCursor(usePlugin bool, e *tcell.EventMouse) bool {
|
func (v *View) MouseMultiCursor(usePlugin bool, e *tcell.EventMouse) bool {
|
||||||
if v.Cursor == &v.Buf.Cursor {
|
if v.Cursor == &v.Buf.Cursor {
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
||||||
"ScrollUp": (*View).ScrollUpAction,
|
"ScrollUp": (*View).ScrollUpAction,
|
||||||
"ScrollDown": (*View).ScrollDownAction,
|
"ScrollDown": (*View).ScrollDownAction,
|
||||||
"SpawnMultiCursor": (*View).SpawnMultiCursor,
|
"SpawnMultiCursor": (*View).SpawnMultiCursor,
|
||||||
|
"SpawnMultiCursorSelect":(*View).SpawnMultiCursorSelect,
|
||||||
"RemoveMultiCursor": (*View).RemoveMultiCursor,
|
"RemoveMultiCursor": (*View).RemoveMultiCursor,
|
||||||
"RemoveAllMultiCursors": (*View).RemoveAllMultiCursors,
|
"RemoveAllMultiCursors": (*View).RemoveAllMultiCursors,
|
||||||
"SkipMultiCursor": (*View).SkipMultiCursor,
|
"SkipMultiCursor": (*View).SkipMultiCursor,
|
||||||
|
|
@ -600,6 +601,7 @@ func DefaultBindings() map[string]string {
|
||||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||||
|
|
||||||
"Alt-n": "SpawnMultiCursor",
|
"Alt-n": "SpawnMultiCursor",
|
||||||
|
"CtrlM": "SpawnMultiCursorSelect",
|
||||||
"Alt-p": "RemoveMultiCursor",
|
"Alt-p": "RemoveMultiCursor",
|
||||||
"Alt-c": "RemoveAllMultiCursors",
|
"Alt-c": "RemoveAllMultiCursors",
|
||||||
"Alt-x": "SkipMultiCursor",
|
"Alt-x": "SkipMultiCursor",
|
||||||
|
|
|
||||||
|
|
@ -464,6 +464,7 @@ MouseWheelRight
|
||||||
|
|
||||||
// Multiple cursors bindings
|
// Multiple cursors bindings
|
||||||
"Alt-n": "SpawnMultiCursor",
|
"Alt-n": "SpawnMultiCursor",
|
||||||
|
"CtrlM": "SpawnMultiCursorSelect",
|
||||||
"Alt-p": "RemoveMultiCursor",
|
"Alt-p": "RemoveMultiCursor",
|
||||||
"Alt-c": "RemoveAllMultiCursors",
|
"Alt-c": "RemoveAllMultiCursors",
|
||||||
"Alt-x": "SkipMultiCursor",
|
"Alt-x": "SkipMultiCursor",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue