mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-25 18:07:07 +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:
@@ -1163,7 +1163,9 @@ func (h *BufPane) DiffPrevious() bool {
|
|||||||
|
|
||||||
// Undo undoes the last action
|
// Undo undoes the last action
|
||||||
func (h *BufPane) Undo() bool {
|
func (h *BufPane) Undo() bool {
|
||||||
h.Buf.Undo()
|
if !h.Buf.Undo() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
InfoBar.Message("Undid action")
|
InfoBar.Message("Undid action")
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
@@ -1171,7 +1173,9 @@ func (h *BufPane) Undo() bool {
|
|||||||
|
|
||||||
// Redo redoes the last action
|
// Redo redoes the last action
|
||||||
func (h *BufPane) Redo() bool {
|
func (h *BufPane) Redo() bool {
|
||||||
h.Buf.Redo()
|
if !h.Buf.Redo() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
InfoBar.Message("Redid action")
|
InfoBar.Message("Redid action")
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -253,11 +253,11 @@ func (eh *EventHandler) Execute(t *TextEvent) {
|
|||||||
ExecuteTextEvent(t, eh.buf)
|
ExecuteTextEvent(t, eh.buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undo the first event in the undo stack
|
// Undo the first event in the undo stack. Returns false if the stack is empty.
|
||||||
func (eh *EventHandler) Undo() {
|
func (eh *EventHandler) Undo() bool {
|
||||||
t := eh.UndoStack.Peek()
|
t := eh.UndoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||||
@@ -266,15 +266,16 @@ func (eh *EventHandler) Undo() {
|
|||||||
for {
|
for {
|
||||||
t = eh.UndoStack.Peek()
|
t = eh.UndoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
eh.UndoOneEvent()
|
eh.UndoOneEvent()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// UndoOneEvent undoes one event
|
// UndoOneEvent undoes one event
|
||||||
@@ -303,11 +304,11 @@ func (eh *EventHandler) UndoOneEvent() {
|
|||||||
eh.RedoStack.Push(t)
|
eh.RedoStack.Push(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redo the first event in the redo stack
|
// Redo the first event in the redo stack. Returns false if the stack is empty.
|
||||||
func (eh *EventHandler) Redo() {
|
func (eh *EventHandler) Redo() bool {
|
||||||
t := eh.RedoStack.Peek()
|
t := eh.RedoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||||
@@ -316,15 +317,16 @@ func (eh *EventHandler) Redo() {
|
|||||||
for {
|
for {
|
||||||
t = eh.RedoStack.Peek()
|
t = eh.RedoStack.Peek()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
eh.RedoOneEvent()
|
eh.RedoOneEvent()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedoOneEvent redoes one event
|
// RedoOneEvent redoes one event
|
||||||
|
|||||||
Reference in New Issue
Block a user