src/Tools/jEdit/src/rendering.scala
changeset 63544 e0cd6469a6b8
parent 63474 f66e3c3b0fb1
child 63681 d2448471ffba
equal deleted inserted replaced
63543:e6e057c01401 63544:e0cd6469a6b8
   411   }
   411   }
   412 
   412 
   413 
   413 
   414   /* caret focus */
   414   /* caret focus */
   415 
   415 
       
   416   def entity_focus(range: Text.Range,
       
   417     check: (Boolean, Long) => Boolean = (is_def: Boolean, i: Long) => is_def): Set[Long] =
       
   418   {
       
   419     val results =
       
   420       snapshot.cumulate[Set[Long]](range, Set.empty, Rendering.caret_focus_elements, _ =>
       
   421           {
       
   422             case (serials, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
       
   423               props match {
       
   424                 case Markup.Entity.Def(i) if check(true, i) => Some(serials + i)
       
   425                 case Markup.Entity.Ref(i) if check(false, i) => Some(serials + i)
       
   426                 case _ => None
       
   427               }
       
   428             case _ => None
       
   429           })
       
   430     (Set.empty[Long] /: results){ case (s1, Text.Info(_, s2)) => s1 ++ s2 }
       
   431   }
       
   432 
   416   def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Set[Long] =
   433   def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Set[Long] =
   417   {
   434   {
   418     def focus(is_def: Boolean): Set[Long] =
   435     val focus_defs = entity_focus(caret_range)
   419     {
       
   420       val results =
       
   421         snapshot.cumulate[Set[Long]](caret_range, Set.empty, Rendering.caret_focus_elements, _ =>
       
   422             {
       
   423               case (serials, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
       
   424                 props match {
       
   425                   case Markup.Entity.Def(i) if is_def => Some(serials + i)
       
   426                   case Markup.Entity.Ref(i) if !is_def => Some(serials + i)
       
   427                   case _ => None
       
   428                 }
       
   429               case _ => None
       
   430             })
       
   431       (Set.empty[Long] /: results){ case (s1, Text.Info(_, s2)) => s1 ++ s2 }
       
   432     }
       
   433 
       
   434     val focus_defs = focus(true)
       
   435 
       
   436     if (focus_defs.nonEmpty) focus_defs
   436     if (focus_defs.nonEmpty) focus_defs
   437     else {
   437     else {
   438       val focus_refs = focus(false)
   438       val visible_defs = entity_focus(visible_range)
   439       def visible_def: Boolean =
   439       entity_focus(caret_range, (is_def: Boolean, i: Long) => !is_def && visible_defs.contains(i))
   440         snapshot.cumulate[Boolean](visible_range, false, Rendering.caret_focus_elements, _ =>
       
   441           {
       
   442             case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
       
   443               props match {
       
   444                 case Markup.Entity.Def(i) if focus_refs(i) => Some(true)
       
   445                 case _ => None
       
   446               }
       
   447           }).exists(info => info.info)
       
   448       if (focus_refs.nonEmpty && visible_def) focus_refs
       
   449       else Set.empty[Long]
       
   450     }
   440     }
   451   }
   441   }
   452 
   442 
   453   def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] =
   443   def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] =
   454   {
   444   {