mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-21 00:07:16 +09:00
Fix multi cursor relocate
This commit is contained in:
@@ -242,11 +242,13 @@ func (b *Buffer) SetName(s string) {
|
||||
|
||||
func (b *Buffer) Insert(start Loc, text []byte) {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
b.EventHandler.Insert(start, text)
|
||||
}
|
||||
|
||||
func (b *Buffer) Remove(start, end Loc) {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
b.EventHandler.Remove(start, end)
|
||||
}
|
||||
|
||||
@@ -428,12 +430,14 @@ func (b *Buffer) IndentString(tabsize int) []byte {
|
||||
func (b *Buffer) SetCursors(c []*Cursor) {
|
||||
b.cursors = c
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
}
|
||||
|
||||
// AddCursor adds a new cursor to the list
|
||||
func (b *Buffer) AddCursor(c *Cursor) {
|
||||
b.cursors = append(b.cursors, c)
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
b.UpdateCursors()
|
||||
}
|
||||
|
||||
@@ -489,10 +493,13 @@ func (b *Buffer) MergeCursors() {
|
||||
b.curCursor = len(b.cursors) - 1
|
||||
}
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
}
|
||||
|
||||
// UpdateCursors updates all the cursors indicies
|
||||
func (b *Buffer) UpdateCursors() {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
for i, c := range b.cursors {
|
||||
c.Num = i
|
||||
}
|
||||
@@ -502,6 +509,8 @@ func (b *Buffer) RemoveCursor(i int) {
|
||||
copy(b.cursors[i:], b.cursors[i+1:])
|
||||
b.cursors[len(b.cursors)-1] = nil
|
||||
b.cursors = b.cursors[:len(b.cursors)-1]
|
||||
b.curCursor = Clamp(b.curCursor, 0, len(b.cursors)-1)
|
||||
b.UpdateCursors()
|
||||
}
|
||||
|
||||
// ClearCursors removes all extra cursors
|
||||
|
||||
@@ -69,6 +69,7 @@ func UndoTextEvent(t *TextEvent, buf *SharedBuffer) {
|
||||
type EventHandler struct {
|
||||
buf *SharedBuffer
|
||||
cursors []*Cursor
|
||||
active int
|
||||
UndoStack *TEStack
|
||||
RedoStack *TEStack
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func (eh *EventHandler) ApplyDiff(str string) {
|
||||
// Insert creates an insert text event and executes it
|
||||
func (eh *EventHandler) Insert(start Loc, text []byte) {
|
||||
e := &TextEvent{
|
||||
C: *eh.cursors[0],
|
||||
C: *eh.cursors[eh.active],
|
||||
EventType: TextEventInsert,
|
||||
Deltas: []Delta{{text, start, Loc{0, 0}}},
|
||||
Time: time.Now(),
|
||||
@@ -136,7 +137,7 @@ func (eh *EventHandler) Insert(start Loc, text []byte) {
|
||||
// Remove creates a remove text event and executes it
|
||||
func (eh *EventHandler) Remove(start, end Loc) {
|
||||
e := &TextEvent{
|
||||
C: *eh.cursors[0],
|
||||
C: *eh.cursors[eh.active],
|
||||
EventType: TextEventRemove,
|
||||
Deltas: []Delta{{[]byte{}, start, end}},
|
||||
Time: time.Now(),
|
||||
@@ -164,7 +165,7 @@ func (eh *EventHandler) Remove(start, end Loc) {
|
||||
// MultipleReplace creates an multiple insertions executes them
|
||||
func (eh *EventHandler) MultipleReplace(deltas []Delta) {
|
||||
e := &TextEvent{
|
||||
C: *eh.cursors[0],
|
||||
C: *eh.cursors[eh.active],
|
||||
EventType: TextEventReplace,
|
||||
Deltas: deltas,
|
||||
Time: time.Now(),
|
||||
|
||||
@@ -144,7 +144,6 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b
|
||||
l := b.lines[i].data
|
||||
charpos := 0
|
||||
|
||||
// TODO: replace within X coords of selection
|
||||
if start.Y == end.Y && i == start.Y {
|
||||
l = util.SliceStart(l, end.X)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
|
||||
Reference in New Issue
Block a user