mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
Fix bugs with undo/redo
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user