mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Image Editor - Allow undoing back to the original state when exceeds the undo limit.
This commit is contained in:
parent
10ad3fbf82
commit
0a7970ad0c
@ -13,7 +13,9 @@ import java.util.Stack;
|
|||||||
* <p>
|
* <p>
|
||||||
* Elements are mutable, so this stack serializes the element and keeps a stack of serialized data.
|
* Elements are mutable, so this stack serializes the element and keeps a stack of serialized data.
|
||||||
* <p>
|
* <p>
|
||||||
* 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 {
|
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
|
* Pushes an element to the stack iff the element's serialized value is different to any found at
|
||||||
* the top of the stack.
|
* the top of the stack.
|
||||||
|
* <p>
|
||||||
|
* Removes the second to earliest item if it is overflowing.
|
||||||
*
|
*
|
||||||
* @param element new editor element state.
|
* @param element new editor element state.
|
||||||
* @return true iff the pushed item was different to the top item.
|
* @return true iff the pushed item was different to the top item.
|
||||||
@ -46,7 +50,7 @@ final class ElementStack implements Parcelable {
|
|||||||
if (push) {
|
if (push) {
|
||||||
stack.push(bytes);
|
stack.push(bytes);
|
||||||
if (stack.size() > limit) {
|
if (stack.size() > limit) {
|
||||||
stack.remove(0);
|
stack.remove(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return push;
|
return push;
|
||||||
|
Loading…
Reference in New Issue
Block a user