Created
January 7, 2021 13:50
-
-
Save le0nidas/9f02e58faf1bc29221dc7de80554832a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Editor { | |
// ... | |
fun backup(): Memento { | |
return ActualMemento(text, caretPosition) | |
} | |
fun restore(memento: Memento) { | |
memento as ActualMemento | |
text.clear() | |
text.addAll(memento.text) | |
caretPosition = memento.caretPosition | |
} | |
// ... | |
open inner class Memento | |
private inner class ActualMemento(text: List<String>, caretPosition: Int) : Memento() { | |
val text: List<String> | |
val caretPosition: Int | |
init { | |
this.text = ArrayList(text) | |
this.caretPosition = caretPosition | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment