From 0a7970ad0cb6afd0f7576716b5cbbe7d00486549 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Wed, 22 May 2019 13:28:02 -0300 Subject: [PATCH] Image Editor - Allow undoing back to the original state when exceeds the undo limit. --- .../securesms/imageeditor/model/ElementStack.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/imageeditor/model/ElementStack.java b/src/org/thoughtcrime/securesms/imageeditor/model/ElementStack.java index 15e0516143..4eb8aa609e 100644 --- a/src/org/thoughtcrime/securesms/imageeditor/model/ElementStack.java +++ b/src/org/thoughtcrime/securesms/imageeditor/model/ElementStack.java @@ -13,7 +13,9 @@ import java.util.Stack; *

* Elements are mutable, so this stack serializes the element and keeps a stack of serialized data. *

- * The stack has a {@link #limit} and if it exceeds that limit during a push the earliest item is removed. + * The stack has a {@link #limit} and if it exceeds that limit during a push the second to earliest item + * is removed so that it can always go back to the first state. Effectively collapsing the history for + * the start of the stack. */ final class ElementStack implements Parcelable { @@ -35,6 +37,8 @@ final class ElementStack implements Parcelable { /** * Pushes an element to the stack iff the element's serialized value is different to any found at * the top of the stack. + *

+ * Removes the second to earliest item if it is overflowing. * * @param element new editor element state. * @return true iff the pushed item was different to the top item. @@ -46,7 +50,7 @@ final class ElementStack implements Parcelable { if (push) { stack.push(bytes); if (stack.size() > limit) { - stack.remove(0); + stack.remove(1); } } return push;