mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-24 17:50:15 +09:00
Improve Undo & Redo actions return values
Return false if there is nothing to undo/redo. This also fixes false "Undid action" and "Redid actions" infobar messages in the case when no action was actually undone or redone.
This commit is contained in:
@@ -253,11 +253,11 @@ func (eh *EventHandler) Execute(t *TextEvent) {
|
||||
ExecuteTextEvent(t, eh.buf)
|
||||
}
|
||||
|
||||
// Undo the first event in the undo stack
|
||||
func (eh *EventHandler) Undo() {
|
||||
// Undo the first event in the undo stack. Returns false if the stack is empty.
|
||||
func (eh *EventHandler) Undo() bool {
|
||||
t := eh.UndoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||
@@ -266,15 +266,16 @@ func (eh *EventHandler) Undo() {
|
||||
for {
|
||||
t = eh.UndoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
eh.UndoOneEvent()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// UndoOneEvent undoes one event
|
||||
@@ -303,11 +304,11 @@ func (eh *EventHandler) UndoOneEvent() {
|
||||
eh.RedoStack.Push(t)
|
||||
}
|
||||
|
||||
// Redo the first event in the redo stack
|
||||
func (eh *EventHandler) Redo() {
|
||||
// Redo the first event in the redo stack. Returns false if the stack is empty.
|
||||
func (eh *EventHandler) Redo() bool {
|
||||
t := eh.RedoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||
@@ -316,15 +317,16 @@ func (eh *EventHandler) Redo() {
|
||||
for {
|
||||
t = eh.RedoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
eh.RedoOneEvent()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// RedoOneEvent redoes one event
|
||||
|
||||
Reference in New Issue
Block a user