Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Editor {
// ...
fun backup(): Memento {
return ActualMemento(text, caretPosition)
fun restore(memento: Memento) {
memento as ActualMemento
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