some rendering of completion range;
authorwenzelm
Sun, 23 Feb 2014 15:35:19 +0100
changeset 55688 767edb2c1e4e
parent 55687 78c83cd477c1
child 55689 13b58baf994b
some rendering of completion range; tuned;
src/Tools/jEdit/src/rendering.scala
src/Tools/jEdit/src/rich_text_area.scala
--- a/src/Tools/jEdit/src/rendering.scala	Sun Feb 23 14:39:51 2014 +0100
+++ b/src/Tools/jEdit/src/rendering.scala	Sun Feb 23 15:35:19 2014 +0100
@@ -273,35 +273,39 @@
 
   /* completion */
 
+  def completion_range(caret: Text.Offset): Option[Text.Range] =
+    if (!snapshot.is_outdated) {
+      snapshot.select(Text.Range(caret - 1, caret + 1), Rendering.completion_names_elements, _ =>
+        {
+          case Completion.Names.Info(names) => Some(names.range)
+          case _ => None
+        }).headOption.map(_.info)
+    }
+    else None
+
   def completion_names(caret: Text.Offset): Option[Completion.Names] =
     if (caret > 0 && !snapshot.is_outdated)
     {
-      val result =
-        snapshot.select(Text.Range(caret - 1, caret + 1),
-          Rendering.completion_names_elements, _ =>
-          {
-            case Completion.Names.Info(names) => Some(names)
-            case _ => None
-          })
-      result.headOption.map(_.info)
+      snapshot.select(Text.Range(caret - 1, caret + 1), Rendering.completion_names_elements, _ =>
+        {
+          case Completion.Names.Info(names) => Some(names)
+          case _ => None
+        }).headOption.map(_.info)
     }
     else None
 
   def completion_context(caret: Text.Offset): Option[Completion.Context] =
     if (caret > 0) {
-      val result =
-        snapshot.select(Text.Range(caret - 1, caret + 1),
-          Rendering.completion_context_elements, _ =>
-          {
-            case Text.Info(_, elem)
-            if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
-              Some(Completion.Context.ML_inner)
-            case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes), _)) =>
-              Some(Completion.Context(language, symbols, antiquotes))
-            case Text.Info(_, _) =>
-              Some(Completion.Context.inner)
-          })
-      result.headOption.map(_.info)
+      snapshot.select(Text.Range(caret - 1, caret + 1), Rendering.completion_context_elements, _ =>
+        {
+          case Text.Info(_, elem)
+          if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
+            Some(Completion.Context.ML_inner)
+          case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes), _)) =>
+            Some(Completion.Context(language, symbols, antiquotes))
+          case Text.Info(_, _) =>
+            Some(Completion.Context.inner)
+        }).headOption.map(_.info)
     }
     else None
 
--- a/src/Tools/jEdit/src/rich_text_area.scala	Sun Feb 23 14:39:51 2014 +0100
+++ b/src/Tools/jEdit/src/rich_text_area.scala	Sun Feb 23 15:35:19 2014 +0100
@@ -104,6 +104,7 @@
   {
     private var the_text_info: Option[(String, Text.Info[A])] = None
 
+    def is_active: Boolean = the_text_info.isDefined
     def text_info: Option[(String, Text.Info[A])] = the_text_info
     def info: Option[Text.Info[A]] = the_text_info.map(_._2)
 
@@ -223,6 +224,11 @@
 
   /* text background */
 
+  private def get_caret_range(): Text.Range =
+    if (caret_visible && text_area.isCaretVisible)
+      JEdit_Lib.point_range(buffer, text_area.getCaretPosition)
+    else Text.Range(-1)
+
   private val background_painter = new TextAreaExtension
   {
     override def paintScreenLineRange(gfx: Graphics2D,
@@ -300,6 +306,7 @@
     val clip_rect = gfx.getClipBounds
     val painter = text_area.getPainter
     val font_context = painter.getFontRenderContext
+    val caret_range = get_caret_range()
 
     var w = 0.0f
     var chunk = head
@@ -317,11 +324,6 @@
           if (s.isEmpty) 0.0f
           else chunk_font.getStringBounds(s, font_context).getWidth.toFloat
 
-        val caret_range =
-          if (caret_visible && text_area.isCaretVisible)
-            JEdit_Lib.point_range(buffer, text_area.getCaretPosition)
-          else Text.Range(-1)
-
         val markup =
           for {
             r1 <- rendering.text_color(chunk_range, chunk_color)
@@ -441,6 +443,9 @@
       start: Array[Int], end: Array[Int], y: Int, line_height: Int)
     {
       robust_rendering { rendering =>
+        val painter = text_area.getPainter
+        val caret_range = get_caret_range()
+
         for (i <- 0 until physical_lines.length) {
           if (physical_lines(i) != -1) {
             val line_range = Text.Range(start(i), end(i))
@@ -473,6 +478,17 @@
               gfx.setColor(rendering.hyperlink_color)
               gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1)
             }
+
+            // completion range
+            for {
+              caret <- caret_range.try_restrict(line_range)
+              if !hyperlink_area.is_active
+              range <- rendering.completion_range(caret.start)
+              r <- JEdit_Lib.gfx_range(text_area, range)
+            } {
+              gfx.setColor(painter.getCaretColor)
+              gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1)
+            }
           }
         }
       }