adding the undo/redo functionality

This commit is contained in:
tibbi
2018-07-17 21:09:53 +02:00
parent 48f31b8d83
commit 2c3a6937a7
5 changed files with 123 additions and 5 deletions

View File

@ -0,0 +1,35 @@
package com.simplemobiletools.notes.models
import java.util.*
class TextHistory {
var position = 0
val history = LinkedList<TextHistoryItem>()
fun getPrevious(): TextHistoryItem? {
if (position == 0) {
return null
}
position--
return history[position]
}
fun getNext(): TextHistoryItem? {
if (position >= history.size) {
return null
}
val item = history[position]
position++
return item
}
fun add(item: TextHistoryItem) {
while (history.size > position) {
history.removeLast()
}
history.add(item)
position++
}
}

View File

@ -0,0 +1,3 @@
package com.simplemobiletools.notes.models
data class TextHistoryItem(val start: Int, val before: CharSequence?, val after: CharSequence?)