mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
adding the undo/redo functionality
This commit is contained in:
@ -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++
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.simplemobiletools.notes.models
|
||||
|
||||
data class TextHistoryItem(val start: Int, val before: CharSequence?, val after: CharSequence?)
|
Reference in New Issue
Block a user