]> git.lizzy.rs Git - micro.git/commitdiff
Fix bugs with undo/redo
authorZachary Yedidia <zyedidia@gmail.com>
Sun, 20 Mar 2016 00:32:14 +0000 (20:32 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Sun, 20 Mar 2016 00:32:14 +0000 (20:32 -0400)
cursor.go
eventhandler.go
todolist.md

index 15a6d657d370ac6fb7cdf708c59e175d5c6f02a6..d207ddeddf41230965553477b2aa1a1505bcbccf 100644 (file)
--- a/cursor.go
+++ b/cursor.go
@@ -207,8 +207,7 @@ func (c *Cursor) Display() {
        if c.y-c.v.topline < 0 || c.y-c.v.topline > c.v.height-1 {
                c.v.s.HideCursor()
        } else {
-               voffset := NumOccurences(c.v.buf.lines[c.y][:c.x], '\t') * (tabSize - 1)
-               c.v.s.ShowCursor(c.x+voffset+c.v.lineNumOffset, c.y-c.v.topline)
+               c.v.s.ShowCursor(c.GetVisualX()+c.v.lineNumOffset, c.y-c.v.topline)
                // cursorStyle := tcell.StyleDefault.Reverse(true)
                // c.v.s.SetContent(c.x+voffset, c.y-c.v.topline, c.runeUnder(), nil, cursorStyle)
        }
index ff886c0a75c5a13eea030b2a2da54be689913ae7..825542d3bc9d9609e8121b1ff49737e2d49a9bfb 100644 (file)
@@ -61,7 +61,7 @@ func (eh *EventHandler) Insert(start int, text string) {
                eventType: TextEventInsert,
                text:      text,
                start:     start,
-               end:       start + len(text),
+               end:       start + Count(text),
                buf:       eh.v.buf,
                time:      time.Now(),
        }
@@ -83,6 +83,9 @@ func (eh *EventHandler) Remove(start, end int) {
 
 // Execute a textevent and add it to the undo stack
 func (eh *EventHandler) Execute(t *TextEvent) {
+       if eh.redo.Len() > 0 {
+               eh.redo = new(Stack)
+       }
        eh.undo.Push(t)
        ExecuteTextEvent(t)
 }
@@ -97,9 +100,12 @@ func (eh *EventHandler) Undo() {
        te := t.(*TextEvent)
        // Modifies the text event
        UndoTextEvent(te)
-       eh.redo.Push(t)
 
-       eh.v.cursor = te.c
+       teCursor := te.c
+       te.c = eh.v.cursor
+       eh.v.cursor = teCursor
+
+       eh.redo.Push(te)
 }
 
 // Redo the first event in the redo stack
@@ -112,6 +118,10 @@ func (eh *EventHandler) Redo() {
        te := t.(*TextEvent)
        // Modifies the text event
        UndoTextEvent(te)
-       eh.undo.Push(t)
-       eh.v.cursor = te.c
+
+       teCursor := te.c
+       te.c = eh.v.cursor
+       eh.v.cursor = teCursor
+
+       eh.undo.Push(te)
 }
index e8078867f83bd3dbedfa44b46767d60e898df2eb..a31a50f4a86b5d209d4f53b782c5f8745f05f6fa 100644 (file)
@@ -21,9 +21,8 @@
     - [ ] Help screen which lists keybindings and commands
     - [ ] Opened with Ctrl-h
 
-- [ ] Undo/redo
+- [x] Undo/redo
     - [x] Undo/redo stack
-    - [ ] Functionality similar to nano
 
 - [x] Clipboard support
     - [x] Ctrl-v, Ctrl-c, and Ctrl-x