author | wenzelm |
Sat, 17 Sep 2011 21:28:52 +0200 | |
changeset 44957 | 098dd95349e7 |
parent 44676 | 7de87f1ae965 |
child 44959 | 9476c856c4b9 |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/PIDE/document.scala |
2 |
Author: Makarius |
|
3 |
||
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
4 |
Document as collection of named nodes, each consisting of an editable |
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
5 |
list of commands, associated with asynchronous execution process. |
36676 | 6 |
*/ |
34407 | 7 |
|
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34868
diff
changeset
|
8 |
package isabelle |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
11 |
import scala.collection.mutable |
37073 | 12 |
|
13 |
||
34823 | 14 |
object Document |
34483 | 15 |
{ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
16 |
/* formal identifiers */ |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
17 |
|
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
18 |
type ID = Long |
43780 | 19 |
val ID = Properties.Value.Long |
38414
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
20 |
|
38373 | 21 |
type Version_ID = ID |
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
22 |
type Command_ID = ID |
38373 | 23 |
type Exec_ID = ID |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
24 |
|
43662
e3175ec00311
Document.no_id/new_id as in ML (new_id *could* be session-specific but it isn't right now);
wenzelm
parents:
43427
diff
changeset
|
25 |
val no_id: ID = 0 |
e3175ec00311
Document.no_id/new_id as in ML (new_id *could* be session-specific but it isn't right now);
wenzelm
parents:
43427
diff
changeset
|
26 |
val new_id = new Counter |
38355
8cb265fb12fe
represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents:
38227
diff
changeset
|
27 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
28 |
|
34818
7df68a8f0e3e
register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents:
34815
diff
changeset
|
29 |
|
38424 | 30 |
/** document structure **/ |
31 |
||
32 |
/* named nodes -- development graph */ |
|
33 |
||
44615 | 34 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 35 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
36 |
type Edit_Command = Edit[(Option[Command], Option[Command]), Command.Perspective] |
|
38151 | 37 |
|
44182 | 38 |
type Node_Header = Exn.Result[Thy_Header] |
39 |
||
38151 | 40 |
object Node |
41 |
{ |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
42 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
43 |
{ |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
44 |
val empty = Name("", "", "") |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
45 |
} |
44616 | 46 |
sealed case class Name(node: String, dir: String, theory: String) |
44615 | 47 |
{ |
48 |
override def hashCode: Int = node.hashCode |
|
49 |
override def equals(that: Any): Boolean = |
|
50 |
that match { |
|
51 |
case other: Name => node == other.node |
|
52 |
case _ => false |
|
53 |
} |
|
44642 | 54 |
override def toString: String = theory |
44615 | 55 |
} |
56 |
||
44384 | 57 |
sealed abstract class Edit[A, B] |
44156 | 58 |
{ |
44383 | 59 |
def foreach(f: A => Unit) |
60 |
{ |
|
44156 | 61 |
this match { |
44383 | 62 |
case Edits(es) => es.foreach(f) |
63 |
case _ => |
|
44156 | 64 |
} |
44383 | 65 |
} |
44156 | 66 |
} |
44384 | 67 |
case class Clear[A, B]() extends Edit[A, B] |
68 |
case class Edits[A, B](edits: List[A]) extends Edit[A, B] |
|
69 |
case class Header[A, B](header: Node_Header) extends Edit[A, B] |
|
70 |
case class Perspective[A, B](perspective: B) extends Edit[A, B] |
|
44156 | 71 |
|
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
72 |
def norm_header(f: String => String, g: String => String, header: Node_Header): Node_Header = |
44182 | 73 |
header match { |
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
74 |
case Exn.Res(h) => Exn.capture { h.norm_deps(f, g) } |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
75 |
case exn => exn |
44182 | 76 |
} |
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
77 |
|
44474 | 78 |
val empty: Node = |
79 |
Node(Exn.Exn(ERROR("Bad theory header")), Command.Perspective.empty, Map(), Linear_Set()) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
80 |
|
38426 | 81 |
def command_starts(commands: Iterator[Command], offset: Text.Offset = 0) |
82 |
: Iterator[(Command, Text.Offset)] = |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
83 |
{ |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
84 |
var i = offset |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
85 |
for (command <- commands) yield { |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
86 |
val start = i |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
87 |
i += command.length |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
88 |
(command, start) |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
89 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
90 |
} |
38151 | 91 |
} |
92 |
||
38880
5b4efe90c120
simplified/clarified Document_View.text_area_extension;
wenzelm
parents:
38879
diff
changeset
|
93 |
private val block_size = 1024 |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
94 |
|
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
95 |
sealed case class Node( |
44182 | 96 |
val header: Node_Header, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
97 |
val perspective: Command.Perspective, |
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
98 |
val blobs: Map[String, Blob], |
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
99 |
val commands: Linear_Set[Command]) |
38151 | 100 |
{ |
44443
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
101 |
def clear: Node = Node.empty.copy(header = header) |
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
102 |
|
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
103 |
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
104 |
/* commands */ |
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
105 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
106 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
107 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
108 |
val blocks = new mutable.ListBuffer[(Command, Text.Offset)] |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
109 |
var next_block = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
110 |
var last_stop = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
111 |
for ((command, start) <- Node.command_starts(commands.iterator)) { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
112 |
last_stop = start + command.length |
38885
06582837872b
Node.full_index: allow command spans larger than block_size;
wenzelm
parents:
38882
diff
changeset
|
113 |
while (last_stop + 1 > next_block) { |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
114 |
blocks += (command -> start) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
115 |
next_block += block_size |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
116 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
117 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
118 |
(blocks.toArray, Text.Range(0, last_stop)) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
119 |
} |
38151 | 120 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
121 |
def full_range: Text.Range = full_index._2 |
38151 | 122 |
|
38569 | 123 |
def command_range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
124 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
125 |
if (!commands.isEmpty && full_range.contains(i)) { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
126 |
val (cmd0, start0) = full_index._1(i / block_size) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
127 |
Node.command_starts(commands.iterator(cmd0), start0) dropWhile { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
128 |
case (cmd, start) => start + cmd.length <= i } |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
129 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
130 |
else Iterator.empty |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
131 |
} |
38151 | 132 |
|
38569 | 133 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
134 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 135 |
|
38426 | 136 |
def command_at(i: Text.Offset): Option[(Command, Text.Offset)] = |
38151 | 137 |
{ |
138 |
val range = command_range(i) |
|
139 |
if (range.hasNext) Some(range.next) else None |
|
140 |
} |
|
141 |
||
38426 | 142 |
def proper_command_at(i: Text.Offset): Option[Command] = |
38151 | 143 |
command_at(i) match { |
144 |
case Some((command, _)) => |
|
145 |
commands.reverse_iterator(command).find(cmd => !cmd.is_ignored) |
|
146 |
case None => None |
|
147 |
} |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
148 |
|
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
149 |
def command_start(cmd: Command): Option[Text.Offset] = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
150 |
command_starts.find(_._1 == cmd).map(_._2) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
151 |
|
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
152 |
def command_starts: Iterator[(Command, Text.Offset)] = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
153 |
Node.command_starts(commands.iterator) |
38151 | 154 |
} |
155 |
||
156 |
||
38424 | 157 |
|
158 |
/** versioning **/ |
|
159 |
||
160 |
/* particular document versions */ |
|
34485 | 161 |
|
38417 | 162 |
object Version |
163 |
{ |
|
43722 | 164 |
val init: Version = Version(no_id, Map().withDefaultValue(Node.empty)) |
38417 | 165 |
} |
166 |
||
44615 | 167 |
type Nodes = Map[Node.Name, Node] |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
168 |
sealed case class Version(val id: Version_ID, val nodes: Nodes) |
34660 | 169 |
|
34859 | 170 |
|
38424 | 171 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
172 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
173 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
174 |
{ |
44672 | 175 |
val init: Change = Change(Some(Future.value(Version.init)), Nil, Future.value(Version.init)) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
176 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
177 |
|
43722 | 178 |
sealed case class Change( |
44672 | 179 |
val previous: Option[Future[Version]], |
40479 | 180 |
val edits: List[Edit_Text], |
43722 | 181 |
val version: Future[Version]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
182 |
{ |
44672 | 183 |
def is_finished: Boolean = |
184 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
185 |
version.is_finished |
|
186 |
||
187 |
def truncate: Change = copy(previous = None, edits = Nil) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
188 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
189 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
190 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
191 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
192 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
193 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
194 |
{ |
44672 | 195 |
val init: History = History(List(Change.init)) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
196 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
197 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
198 |
// FIXME pruning, purging of state |
44672 | 199 |
sealed case class History(val undo_list: List[Change]) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
200 |
{ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
201 |
require(!undo_list.isEmpty) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
202 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
203 |
def tip: Change = undo_list.head |
44672 | 204 |
def +(change: Change): History = copy(undo_list = change :: undo_list) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
205 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
206 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
207 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
208 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
209 |
/** global state -- document structure, execution process, editing history **/ |
38424 | 210 |
|
211 |
abstract class Snapshot |
|
212 |
{ |
|
44582 | 213 |
val state: State |
38424 | 214 |
val version: Version |
215 |
val node: Node |
|
216 |
val is_outdated: Boolean |
|
44582 | 217 |
def command_state(command: Command): Command.State |
38427 | 218 |
def convert(i: Text.Offset): Text.Offset |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
219 |
def convert(range: Text.Range): Text.Range |
38427 | 220 |
def revert(i: Text.Offset): Text.Offset |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
221 |
def revert(range: Text.Range): Text.Range |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
222 |
def select_markup[A](range: Text.Range)(result: Markup_Tree.Select[A]) |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
223 |
: Stream[Text.Info[Option[A]]] |
38424 | 224 |
} |
225 |
||
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
226 |
type Assign = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
227 |
(List[(Document.Command_ID, Option[Document.Exec_ID])], // exec state assignment |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
228 |
List[(String, Option[Document.Command_ID])]) // last exec |
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
229 |
|
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
230 |
val no_assign: Assign = (Nil, Nil) |
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
231 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
232 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
233 |
{ |
38373 | 234 |
class Fail(state: State) extends Exception |
235 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
236 |
val init: State = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
237 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id, no_assign)._2 |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
238 |
|
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
239 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
240 |
{ |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
241 |
val init: Assignment = Assignment(Map.empty, Map.empty, false) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
242 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
243 |
|
38976
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
wenzelm
parents:
38885
diff
changeset
|
244 |
case class Assignment( |
44477 | 245 |
val command_execs: Map[Command_ID, Exec_ID], |
246 |
val last_execs: Map[String, Option[Command_ID]], |
|
247 |
val is_finished: Boolean) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
248 |
{ |
44477 | 249 |
def check_finished: Assignment = { require(is_finished); this } |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
250 |
def unfinished: Assignment = copy(is_finished = false) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
251 |
|
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
252 |
def assign(add_command_execs: List[(Command_ID, Option[Exec_ID])], |
44477 | 253 |
add_last_execs: List[(String, Option[Command_ID])]): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
254 |
{ |
38976
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
wenzelm
parents:
38885
diff
changeset
|
255 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
256 |
val command_execs1 = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
257 |
(command_execs /: add_command_execs) { |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
258 |
case (res, (command_id, None)) => res - command_id |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
259 |
case (res, (command_id, Some(exec_id))) => res + (command_id -> exec_id) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
260 |
} |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
261 |
Assignment(command_execs1, last_execs ++ add_last_execs, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
262 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
263 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
264 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
265 |
|
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
266 |
sealed case class State( |
38417 | 267 |
val versions: Map[Version_ID, Version] = Map(), |
44446 | 268 |
val commands: Map[Command_ID, Command.State] = Map(), // static markup from define_command |
269 |
val execs: Map[Exec_ID, Command.State] = Map(), // dynamic markup from execution |
|
43722 | 270 |
val assignments: Map[Version_ID, State.Assignment] = Map(), |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
271 |
val history: History = History.init) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
272 |
{ |
38373 | 273 |
private def fail[A]: A = throw new State.Fail(this) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
274 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
275 |
def define_version(version: Version, assignment: State.Assignment): State = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
276 |
{ |
38417 | 277 |
val id = version.id |
278 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
279 |
assignments = assignments + (id -> assignment.unfinished)) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
280 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
281 |
|
38373 | 282 |
def define_command(command: Command): State = |
283 |
{ |
|
284 |
val id = command.id |
|
285 |
copy(commands = commands + (id -> command.empty_state)) |
|
286 |
} |
|
287 |
||
44582 | 288 |
def defined_command(id: Command_ID): Boolean = commands.isDefinedAt(id) |
289 |
||
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
290 |
def find_command(version: Version, id: ID): Option[(Node, Command)] = |
44582 | 291 |
commands.get(id) orElse execs.get(id) match { |
292 |
case None => None |
|
293 |
case Some(st) => |
|
294 |
val command = st.command |
|
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
295 |
version.nodes.get(command.node_name).map((_, command)) |
44582 | 296 |
} |
38373 | 297 |
|
38417 | 298 |
def the_version(id: Version_ID): Version = versions.getOrElse(id, fail) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
299 |
def the_command(id: Command_ID): Command.State = commands.getOrElse(id, fail) // FIXME rename |
44446 | 300 |
def the_exec(id: Exec_ID): Command.State = execs.getOrElse(id, fail) |
43722 | 301 |
def the_assignment(version: Version): State.Assignment = |
302 |
assignments.getOrElse(version.id, fail) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
303 |
|
38872 | 304 |
def accumulate(id: ID, message: XML.Elem): (Command.State, State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
305 |
execs.get(id) match { |
44446 | 306 |
case Some(st) => |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
307 |
val new_st = st.accumulate(message) |
44446 | 308 |
(new_st, copy(execs = execs + (id -> new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
309 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
310 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
311 |
case Some(st) => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
312 |
val new_st = st.accumulate(message) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
313 |
(new_st, copy(commands = commands + (id -> new_st))) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
314 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
315 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
316 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
317 |
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
318 |
def assign(id: Version_ID, arg: Assign): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
319 |
{ |
38417 | 320 |
val version = the_version(id) |
44477 | 321 |
val (command_execs, last_execs) = arg |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
322 |
|
44543 | 323 |
val (changed_commands, new_execs) = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
324 |
((Nil: List[Command], execs) /: command_execs) { |
44543 | 325 |
case ((commands1, execs1), (cmd_id, exec)) => |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
326 |
val st = the_command(cmd_id) |
44543 | 327 |
val commands2 = st.command :: commands1 |
328 |
val execs2 = |
|
329 |
exec match { |
|
330 |
case None => execs1 |
|
331 |
case Some(exec_id) => execs1 + (exec_id -> st) |
|
332 |
} |
|
333 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
334 |
} |
44477 | 335 |
val new_assignment = the_assignment(version).assign(command_execs, last_execs) |
43722 | 336 |
val new_state = copy(assignments = assignments + (id -> new_assignment), execs = new_execs) |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
337 |
|
44543 | 338 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
339 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
340 |
|
38417 | 341 |
def is_assigned(version: Version): Boolean = |
43722 | 342 |
assignments.get(version.id) match { |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
343 |
case Some(assgn) => assgn.is_finished |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
344 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
345 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
346 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
347 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
348 |
change.is_finished && is_assigned(change.version.get_finished) |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
349 |
|
44672 | 350 |
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
351 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 352 |
def tip_version: Version = history.tip.version.get_finished |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
353 |
|
44615 | 354 |
def last_exec_offset(name: Node.Name): Text.Offset = |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
355 |
{ |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
356 |
val version = tip_version |
44615 | 357 |
the_assignment(version).last_execs.get(name.node) match { |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
358 |
case Some(Some(id)) => |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
359 |
val node = version.nodes(name) |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
360 |
val cmd = the_command(id).command |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
361 |
node.command_start(cmd) match { |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
362 |
case None => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
363 |
case Some(start) => start + cmd.length |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
364 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
365 |
case _ => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
366 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
367 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
368 |
|
44446 | 369 |
def continue_history( |
370 |
previous: Future[Version], |
|
40479 | 371 |
edits: List[Edit_Text], |
43722 | 372 |
version: Future[Version]): (Change, State) = |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
373 |
{ |
44672 | 374 |
val change = Change(Some(previous), edits, version) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
375 |
(change, copy(history = history + change)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
376 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
377 |
|
44672 | 378 |
def prune_history(retain: Int = 0): (List[Version], State) = |
379 |
{ |
|
380 |
val undo_list = history.undo_list |
|
381 |
val n = undo_list.iterator.zipWithIndex.find(p => is_stable(p._1)).get._2 + 1 |
|
382 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
383 |
||
384 |
retained.splitAt(retained.length - 1) match { |
|
385 |
case (prefix, List(last)) => |
|
386 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
|
387 |
val state1 = copy(history = History(prefix ::: List(last.truncate))) |
|
388 |
(dropped_versions, state1) |
|
389 |
case _ => fail |
|
390 |
} |
|
391 |
} |
|
392 |
||
44676 | 393 |
def removed_versions(removed: List[Version_ID]): State = |
394 |
{ |
|
395 |
val versions1 = versions -- removed |
|
396 |
val assignments1 = assignments -- removed |
|
397 |
var commands1 = Map.empty[Command_ID, Command.State] |
|
398 |
var execs1 = Map.empty[Exec_ID, Command.State] |
|
399 |
for { |
|
400 |
(version_id, version) <- versions1.iterator |
|
401 |
val command_execs = assignments1(version_id).command_execs |
|
402 |
(_, node) <- version.nodes.iterator |
|
403 |
command <- node.commands.iterator |
|
404 |
} { |
|
405 |
val id = command.id |
|
406 |
if (!commands1.isDefinedAt(id) && commands.isDefinedAt(id)) |
|
407 |
commands1 += (id -> commands(id)) |
|
408 |
if (command_execs.isDefinedAt(id)) { |
|
409 |
val exec_id = command_execs(id) |
|
410 |
if (!execs1.isDefinedAt(exec_id) && execs.isDefinedAt(exec_id)) |
|
411 |
execs1 += (exec_id -> execs(exec_id)) |
|
412 |
} |
|
413 |
} |
|
414 |
copy(versions = versions1, commands = commands1, execs = execs1, assignments = assignments1) |
|
415 |
} |
|
416 |
||
44613 | 417 |
def command_state(version: Version, command: Command): Command.State = |
418 |
{ |
|
419 |
require(is_assigned(version)) |
|
420 |
try { |
|
421 |
the_exec(the_assignment(version).check_finished.command_execs |
|
422 |
.getOrElse(command.id, fail)) |
|
423 |
} |
|
424 |
catch { case _: State.Fail => command.empty_state } |
|
425 |
} |
|
426 |
||
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
427 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
428 |
// persistent user-view |
44615 | 429 |
def snapshot(name: Node.Name, pending_edits: List[Text.Edit]): Snapshot = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
430 |
{ |
44672 | 431 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
432 |
val latest = history.tip |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
433 |
|
44156 | 434 |
// FIXME proper treatment of removed nodes |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
435 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
436 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 437 |
(for ((a, Node.Edits(es)) <- change.edits if a == name) yield es).flatten ::: edits) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
438 |
lazy val reverse_edits = edits.reverse |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
439 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
440 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
441 |
{ |
44582 | 442 |
val state = State.this |
39698 | 443 |
val version = stable.version.get_finished |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
444 |
val node = version.nodes(name) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
445 |
val is_outdated = !(pending_edits.isEmpty && latest == stable) |
44613 | 446 |
def command_state(command: Command): Command.State = state.command_state(version, command) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
447 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
448 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
449 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 450 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
451 |
def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r)) |
|
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
452 |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
39177
diff
changeset
|
453 |
def select_markup[A](range: Text.Range)(result: Markup_Tree.Select[A]) |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
454 |
: Stream[Text.Info[Option[A]]] = |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
455 |
{ |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
456 |
val former_range = revert(range) |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
457 |
for { |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
458 |
(command, command_start) <- node.command_range(former_range).toStream |
44582 | 459 |
Text.Info(r0, x) <- command_state(command).markup. |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
460 |
select((former_range - command_start).restrict(command.range)) { |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
461 |
case Text.Info(r0, info) |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
462 |
if result.isDefinedAt(Text.Info(convert(r0 + command_start), info)) => |
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
463 |
result(Text.Info(convert(r0 + command_start), info)) |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
464 |
} |
43427
5c716a68931a
select_markup: no filtering here -- results may be distorted anyway;
wenzelm
parents:
43425
diff
changeset
|
465 |
} yield Text.Info(convert(r0 + command_start), x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
466 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
467 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
468 |
} |
34485 | 469 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
470 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
471 |