159 /* update to desired version */ |
159 /* update to desired version */ |
160 |
160 |
161 def set_version(id: String) { |
161 def set_version(id: String) { |
162 // changes in buffer must be ignored |
162 // changes in buffer must be ignored |
163 buffer.removeBufferListener(this) |
163 buffer.removeBufferListener(this) |
164 buffer.remove(0, buffer.getLength) |
164 |
165 val to_undo = changes.takeWhile(_.id != id) |
165 val base = changes.find(_.id == doc_id).get |
166 to_undo.map { c => |
166 val goal = changes.find(_.id == id).get |
167 buffer.remove(c.start, c.added.length) |
167 |
168 buffer.insert(c.start, c.removed) |
168 if (changes.indexOf(base) < changes.indexOf(goal)) |
169 } |
169 changes.dropWhile(_ != base).takeWhile(_ != goal).map { c => |
|
170 buffer.remove(c.start, c.added.length) |
|
171 buffer.insert(c.start, c.removed)} |
|
172 else |
|
173 changes.dropWhile(_ != goal).takeWhile(_ != base).reverse.map { c => |
|
174 buffer.remove(c.start, c.removed.length) |
|
175 buffer.insert(c.start, c.added)} |
|
176 |
|
177 val content = buffer.getText(0, buffer.getLength) |
170 doc_id = id |
178 doc_id = id |
171 /* listen for changes again (TODO: can it be that Listener gets events that |
179 /* listen for changes again (TODO: can it be that Listener gets events that |
172 happenend prior to registration??) */ |
180 happenend prior to registration??) */ |
173 buffer.addBufferListener(this) |
181 buffer.addBufferListener(this) |
174 } |
182 } |
249 |
257 |
250 /* BufferListener methods */ |
258 /* BufferListener methods */ |
251 |
259 |
252 private var changes: List[Text.Change] = Nil |
260 private var changes: List[Text.Change] = Nil |
253 private def current_changes = changes.dropWhile(_.id != doc_id) |
261 private def current_changes = changes.dropWhile(_.id != doc_id) |
|
262 def get_changes = changes |
254 |
263 |
255 private def commit: Unit = synchronized { |
264 private def commit: Unit = synchronized { |
256 if (col != null) { |
265 if (col != null) { |
257 def split_changes(c: Text.Change): List[Text.Change] = { |
266 def split_changes(c: Text.Change): List[Text.Change] = { |
258 val MAX = TheoryView.MAX_CHANGE_LENGTH |
267 val MAX = TheoryView.MAX_CHANGE_LENGTH |