Fix multi cursor relocate

This commit is contained in:
Zachary Yedidia
2019-01-16 17:52:30 -05:00
parent 1a710272f8
commit 254b892a3b
6 changed files with 29 additions and 10 deletions

View File

@@ -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(),