src/Pure/Thy/thy_syntax.scala
changeset 52849 199e9fa5a5c2
parent 52808 143f225e50f5
child 52861 e93d73b51fd0
equal deleted inserted replaced
52848:9489ca1d55dd 52849:199e9fa5a5c2
   291 
   291 
   292 
   292 
   293   /* main */
   293   /* main */
   294 
   294 
   295   def diff_commands(old_cmds: Linear_Set[Command], new_cmds: Linear_Set[Command])
   295   def diff_commands(old_cmds: Linear_Set[Command], new_cmds: Linear_Set[Command])
   296     : List[(Option[Command], Option[Command])] =
   296     : List[Command.Edit] =
   297   {
   297   {
   298     val removed = old_cmds.iterator.filter(!new_cmds.contains(_)).toList
   298     val removed = old_cmds.iterator.filter(!new_cmds.contains(_)).toList
   299     val inserted = new_cmds.iterator.filter(!old_cmds.contains(_)).toList
   299     val inserted = new_cmds.iterator.filter(!old_cmds.contains(_)).toList
   300 
   300 
   301     removed.reverse.map(cmd => (old_cmds.prev(cmd), None)) :::
   301     removed.reverse.map(cmd => (old_cmds.prev(cmd), None)) :::
   309       case (_, Document.Node.Clear()) => node.clear
   309       case (_, Document.Node.Clear()) => node.clear
   310 
   310 
   311       case (name, Document.Node.Edits(text_edits)) =>
   311       case (name, Document.Node.Edits(text_edits)) =>
   312         val commands0 = node.commands
   312         val commands0 = node.commands
   313         val commands1 = edit_text(text_edits, commands0)
   313         val commands1 = edit_text(text_edits, commands0)
   314         val commands2 = recover_spans(syntax, name, node.perspective._2, commands1)
   314         val commands2 = recover_spans(syntax, name, node.perspective.visible, commands1)
   315         node.update_commands(commands2)
   315         node.update_commands(commands2)
   316 
   316 
   317       case (_, Document.Node.Deps(_)) => node
   317       case (_, Document.Node.Deps(_)) => node
   318 
   318 
   319       case (name, Document.Node.Perspective(required, text_perspective)) =>
   319       case (name, Document.Node.Perspective(required, text_perspective, overlays)) =>
   320         val perspective = (required, command_perspective(node, text_perspective))
   320         val perspective: Document.Node.Perspective_Command =
       
   321           Document.Node.Perspective(required, command_perspective(node, text_perspective), overlays)
   321         if (node.same_perspective(perspective)) node
   322         if (node.same_perspective(perspective)) node
   322         else
   323         else
   323           node.update_perspective(perspective).update_commands(
   324           node.update_perspective(perspective).update_commands(
   324             consolidate_spans(syntax, reparse_limit, name, perspective._2, node.commands))
   325             consolidate_spans(syntax, reparse_limit, name, perspective.visible, node.commands))
   325     }
   326     }
   326   }
   327   }
   327 
   328 
   328   def text_edits(
   329   def text_edits(
   329       base_syntax: Outer_Syntax,
   330       base_syntax: Outer_Syntax,
   352             node.update_commands(reparse_spans(syntax, name, commands, commands.head, commands.last))
   353             node.update_commands(reparse_spans(syntax, name, commands, commands.head, commands.last))
   353           else node
   354           else node
   354         val node2 = (node1 /: edits)(text_edit(syntax, reparse_limit, _, _))
   355         val node2 = (node1 /: edits)(text_edit(syntax, reparse_limit, _, _))
   355 
   356 
   356         if (!(node.same_perspective(node2.perspective)))
   357         if (!(node.same_perspective(node2.perspective)))
   357           doc_edits +=
   358           doc_edits += (name -> node2.perspective)
   358             (name -> Document.Node.Perspective(node2.perspective._1, node2.perspective._2))
       
   359 
   359 
   360         doc_edits += (name -> Document.Node.Edits(diff_commands(commands, node2.commands)))
   360         doc_edits += (name -> Document.Node.Edits(diff_commands(commands, node2.commands)))
   361 
   361 
   362         nodes += (name -> node2)
   362         nodes += (name -> node2)
   363     }
   363     }