author | wenzelm |
Fri, 01 Jan 2010 21:53:00 +0100 | |
changeset 34827 | 69852bd3c4c4 |
parent 34825 | 7f72547f9b12 |
child 34833 | 683ddf358698 |
permissions | -rw-r--r-- |
34660 | 1 |
/* |
34703 | 2 |
* Changes of plain text |
34660 | 3 |
* |
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle.proofdocument |
|
9 |
||
34703 | 10 |
|
34693 | 11 |
sealed abstract class Edit |
12 |
{ |
|
34660 | 13 |
val start: Int |
34695 | 14 |
def before(offset: Int): Int |
15 |
def after(offset: Int): Int |
|
34660 | 16 |
} |
17 |
||
34703 | 18 |
|
34693 | 19 |
case class Insert(start: Int, text: String) extends Edit |
20 |
{ |
|
34695 | 21 |
def before(offset: Int): Int = |
22 |
if (start > offset) offset |
|
23 |
else (offset - text.length) max start |
|
34660 | 24 |
|
34695 | 25 |
def after(offset: Int): Int = |
26 |
if (start <= offset) offset + text.length else offset |
|
34660 | 27 |
} |
28 |
||
34703 | 29 |
|
34693 | 30 |
case class Remove(start: Int, text: String) extends Edit |
31 |
{ |
|
34695 | 32 |
def before(offset: Int): Int = |
33 |
if (start <= offset) offset + text.length else offset |
|
34660 | 34 |
|
34695 | 35 |
def after(offset: Int): Int = |
36 |
if (start > offset) offset |
|
37 |
else (offset - text.length) max start |
|
34660 | 38 |
} |
39 |
// TODO: merge multiple inserts? |
|
40 |
||
34703 | 41 |
|
34660 | 42 |
class Change( |
43 |
val parent: Option[Change], |
|
34824
ac35eee85f5c
renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents:
34759
diff
changeset
|
44 |
val edits: List[Edit], |
ac35eee85f5c
renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents:
34759
diff
changeset
|
45 |
val result: Future[Document.Result]) |
34660 | 46 |
{ |
34824
ac35eee85f5c
renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents:
34759
diff
changeset
|
47 |
// FIXME iterator |
34693 | 48 |
def ancestors(done: Change => Boolean): List[Change] = |
49 |
if (done(this)) Nil |
|
50 |
else this :: parent.map(_.ancestors(done)).getOrElse(Nil) |
|
34660 | 51 |
def ancestors: List[Change] = ancestors(_ => false) |
52 |
||
34825 | 53 |
def document: Document = result.join._1 |
54 |
def document_edits: List[Document.Structure_Edit] = result.join._2 |
|
34660 | 55 |
} |