src/Pure/PIDE/rendering.scala
changeset 72901 16fd39c9e31f
parent 72900 c9813630cca4
child 72902 3c09adb4b042
equal deleted inserted replaced
72900:c9813630cca4 72901:16fd39c9e31f
   174 
   174 
   175   object Focus
   175   object Focus
   176   {
   176   {
   177     def apply(ids: Set[Long]): Focus = new Focus(ids)
   177     def apply(ids: Set[Long]): Focus = new Focus(ids)
   178     val empty: Focus = apply(Set.empty)
   178     val empty: Focus = apply(Set.empty)
       
   179     def merge(args: TraversableOnce[Focus]): Focus = (empty /: args)(_ ++ _)
   179   }
   180   }
   180 
   181 
   181   sealed class Focus private[Rendering](protected val rep: Set[Long])
   182   sealed class Focus private[Rendering](protected val rep: Set[Long])
   182   {
   183   {
   183     def defined: Boolean = rep.nonEmpty
   184     def defined: Boolean = rep.nonEmpty
   237 
   238 
   238   val message_elements = Markup.Elements(message_pri.keySet)
   239   val message_elements = Markup.Elements(message_pri.keySet)
   239   val warning_elements = Markup.Elements(Markup.WARNING, Markup.LEGACY)
   240   val warning_elements = Markup.Elements(Markup.WARNING, Markup.LEGACY)
   240   val error_elements = Markup.Elements(Markup.ERROR)
   241   val error_elements = Markup.Elements(Markup.ERROR)
   241 
   242 
   242   val entity_focus_elements = Markup.Elements(Markup.ENTITY)
   243   val entity_elements = Markup.Elements(Markup.ENTITY)
   243 
   244 
   244   val antiquoted_elements = Markup.Elements(Markup.ANTIQUOTED)
   245   val antiquoted_elements = Markup.Elements(Markup.ANTIQUOTED)
   245 
   246 
   246   val meta_data_elements =
   247   val meta_data_elements =
   247     Markup.Elements(Markup.META_TITLE, Markup.META_CREATOR, Markup.META_CONTRIBUTOR,
   248     Markup.Elements(Markup.META_TITLE, Markup.META_CREATOR, Markup.META_CONTRIBUTOR,
   500 
   501 
   501   private def entity_focus(range: Text.Range,
   502   private def entity_focus(range: Text.Range,
   502       check: (Boolean, Long) => Boolean = (is_def: Boolean, i: Long) => is_def)
   503       check: (Boolean, Long) => Boolean = (is_def: Boolean, i: Long) => is_def)
   503     : Rendering.Focus =
   504     : Rendering.Focus =
   504   {
   505   {
   505     val results =
   506     Rendering.Focus.merge(
   506       snapshot.cumulate[Rendering.Focus](range, Rendering.Focus.empty,
   507       snapshot.cumulate[Rendering.Focus](range, Rendering.Focus.empty, Rendering.entity_elements,
   507         Rendering.entity_focus_elements, _ =>
   508         _ =>
   508           {
   509           {
   509             case (focus, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   510             case (focus, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   510               props match {
   511               props match {
   511                 case Markup.Entity.Def(i) if check(true, i) => Some(focus + i)
   512                 case Markup.Entity.Def(i) if check(true, i) => Some(focus + i)
   512                 case Markup.Entity.Ref(i) if check(false, i) => Some(focus + i)
   513                 case Markup.Entity.Ref(i) if check(false, i) => Some(focus + i)
   513                 case _ => None
   514                 case _ => None
   514               }
   515               }
   515             case _ => None
   516             case _ => None
   516           })
   517           }).iterator.map(_.info))
   517     (Rendering.Focus.empty /: results){
       
   518       case (focus1, Text.Info(_, focus2)) => focus1 ++ focus2 }
       
   519   }
   518   }
   520 
   519 
   521   def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Rendering.Focus =
   520   def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Rendering.Focus =
   522   {
   521   {
   523     val focus_defs = entity_focus(caret_range)
   522     val focus_defs = entity_focus(caret_range)
   531   def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] =
   530   def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] =
   532   {
   531   {
   533     val focus = caret_focus(caret_range, visible_range)
   532     val focus = caret_focus(caret_range, visible_range)
   534     if (focus.defined) {
   533     if (focus.defined) {
   535       val results =
   534       val results =
   536         snapshot.cumulate[Boolean](visible_range, false, Rendering.entity_focus_elements, _ =>
   535         snapshot.cumulate[Boolean](visible_range, false, Rendering.entity_elements, _ =>
   537           {
   536           {
   538             case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   537             case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   539               props match {
   538               props match {
   540                 case Markup.Entity.Def(i) if focus(i) => Some(true)
   539                 case Markup.Entity.Def(i) if focus(i) => Some(true)
   541                 case Markup.Entity.Ref(i) if focus(i) => Some(true)
   540                 case Markup.Entity.Ref(i) if focus(i) => Some(true)