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) {
if (memento !is ActualMemento) return
caretPosition = memento.caretPosition
// ...
interface Memento
private 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