src/Pure/Thy/thy_syntax.scala
changeset 82791 57527794c788
parent 82789 941b6cdf3611
child 82792 d3f0f72b2c43
equal deleted inserted replaced
82790:42a4d2ab2d54 82791:57527794c788
   118   /** text edits **/
   118   /** text edits **/
   119 
   119 
   120   /* edit individual command source */
   120   /* edit individual command source */
   121 
   121 
   122   @tailrec def edit_text(
   122   @tailrec def edit_text(
   123     eds: List[Text.Edit],
   123     text_edits: List[Text.Edit],
   124     commands: Linear_Set[Command]
   124     commands: Linear_Set[Command]
   125   ): Linear_Set[Command] = {
   125   ): Linear_Set[Command] = {
   126     eds match {
   126     text_edits match {
   127       case e :: es =>
   127       case e :: es =>
   128         def insert_text(cmd: Option[Command], text: String): Linear_Set[Command] =
   128         def insert_text(cmd: Option[Command], text: String): Linear_Set[Command] =
   129           if (text == "") commands else commands.insert_after(cmd, Command.unparsed(text))
   129           if (text.isEmpty) commands else commands.insert_after(cmd, Command.unparsed(text))
   130 
   130 
   131         Document.Node.Commands.starts(commands.iterator).find {
   131         Document.Node.Commands.starts(commands.iterator).find {
   132           case (cmd, cmd_start) =>
   132           case (cmd, cmd_start) =>
   133             e.can_edit(cmd.source, cmd_start) ||
   133             e.can_edit(cmd.source, cmd_start) ||
   134               e.is_insert && e.start == cmd_start + cmd.length
   134               e.is_insert && e.start == cmd_start + cmd.length
   135         } match {
   135         } match {
   136           case Some((cmd, cmd_start)) if e.can_edit(cmd.source, cmd_start) =>
   136           case Some((cmd, cmd_start)) if e.can_edit(cmd.source, cmd_start) =>
   137             val (rest, text) = e.edit(cmd.source, cmd_start)
   137             val (rest, text) = e.edit(cmd.source, cmd_start)
   138             val new_commands = insert_text(Some(cmd), text) - cmd
   138             edit_text(rest.toList ::: es, insert_text(Some(cmd), text) - cmd)
   139             edit_text(rest.toList ::: es, new_commands)
       
   140 
   139 
   141           case Some((cmd, _)) =>
   140           case Some((cmd, _)) =>
   142             edit_text(es, insert_text(Some(cmd), e.text))
   141             edit_text(es, insert_text(Some(cmd), e.text))
   143 
   142 
   144           case None =>
   143           case None =>
   247     edit match {
   246     edit match {
   248       case (_, Document.Node.Blob(blob)) => Document.Node.init_blob(blob)
   247       case (_, Document.Node.Blob(blob)) => Document.Node.init_blob(blob)
   249 
   248 
   250       case (name, Document.Node.Edits(text_edits)) =>
   249       case (name, Document.Node.Edits(text_edits)) =>
   251         if (name.is_theory) {
   250         if (name.is_theory) {
   252           val commands0 = node.commands
   251           val commands1 = edit_text(text_edits, node.commands)
   253           val commands1 = edit_text(text_edits, commands0)
       
   254           val commands2 = recover_spans(name, node.perspective.visible, commands1)
   252           val commands2 = recover_spans(name, node.perspective.visible, commands1)
   255           node.update_commands(commands2)
   253           node.update_commands(commands2)
   256         }
   254         }
   257         else node
   255         else node
   258 
   256