src/Tools/jEdit/src/rich_text_area.scala
changeset 55747 bef19c929ba5
parent 55726 945ad7eaf37f
child 55766 6a16443e520e
     1.1 --- a/src/Tools/jEdit/src/rich_text_area.scala	Tue Feb 25 18:07:35 2014 +0100
     1.2 +++ b/src/Tools/jEdit/src/rich_text_area.scala	Tue Feb 25 20:15:47 2014 +0100
     1.3 @@ -222,23 +222,6 @@
     1.4    }
     1.5  
     1.6  
     1.7 -  /* caret */
     1.8 -
     1.9 -  private def get_caret_range(stretch: Boolean): Text.Range =
    1.10 -    if (caret_visible) {
    1.11 -      val caret = text_area.getCaretPosition
    1.12 -      if (stretch) JEdit_Lib.stretch_point_range(buffer, caret)
    1.13 -      else JEdit_Lib.point_range(buffer, caret)
    1.14 -    }
    1.15 -    else Text.Range(-1)
    1.16 -
    1.17 -  private def get_caret_color(rendering: Rendering): Color =
    1.18 -  {
    1.19 -    if (text_area.isCaretVisible) text_area.getPainter.getCaretColor
    1.20 -    else rendering.caret_invisible_color
    1.21 -  }
    1.22 -
    1.23 -
    1.24    /* text background */
    1.25  
    1.26    private val background_painter = new TextAreaExtension
    1.27 @@ -312,13 +295,23 @@
    1.28  
    1.29    /* text */
    1.30  
    1.31 +  private def caret_color(rendering: Rendering): Color =
    1.32 +  {
    1.33 +    if (text_area.isCaretVisible)
    1.34 +      text_area.getPainter.getCaretColor
    1.35 +    else rendering.caret_invisible_color
    1.36 +  }
    1.37 +
    1.38    private def paint_chunk_list(rendering: Rendering,
    1.39      gfx: Graphics2D, line_start: Text.Offset, head: Chunk, x: Float, y: Float): Float =
    1.40    {
    1.41      val clip_rect = gfx.getClipBounds
    1.42      val painter = text_area.getPainter
    1.43      val font_context = painter.getFontRenderContext
    1.44 -    val caret_range = get_caret_range(false)
    1.45 +
    1.46 +    val caret_range =
    1.47 +      if (caret_visible) JEdit_Lib.point_range(buffer, text_area.getCaretPosition)
    1.48 +      else Text.Range(-1)
    1.49  
    1.50      var w = 0.0f
    1.51      var chunk = head
    1.52 @@ -369,7 +362,7 @@
    1.53  
    1.54                val astr = new AttributedString(s2)
    1.55                astr.addAttribute(TextAttribute.FONT, chunk_font)
    1.56 -              astr.addAttribute(TextAttribute.FOREGROUND, get_caret_color(rendering))
    1.57 +              astr.addAttribute(TextAttribute.FOREGROUND, caret_color(rendering))
    1.58                astr.addAttribute(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON)
    1.59                gfx.drawString(astr.getIterator, x1 + string_width(s1), y)
    1.60  
    1.61 @@ -455,9 +448,6 @@
    1.62        start: Array[Int], end: Array[Int], y: Int, line_height: Int)
    1.63      {
    1.64        robust_rendering { rendering =>
    1.65 -        val caret_range = get_caret_range(true)
    1.66 -        val caret_color = text_area.getPainter.getCaretColor
    1.67 -
    1.68          for (i <- 0 until physical_lines.length) {
    1.69            if (physical_lines(i) != -1) {
    1.70              val line_range = Text.Range(start(i), end(i))
    1.71 @@ -492,21 +482,14 @@
    1.72              }
    1.73  
    1.74              // completion range
    1.75 -            if (!hyperlink_area.is_active) {
    1.76 -              def paint_completion(range: Text.Range) {
    1.77 -                for (r <- JEdit_Lib.gfx_range(text_area, range)) {
    1.78 -                  gfx.setColor(caret_color)
    1.79 -                  gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1)
    1.80 -                }
    1.81 -              }
    1.82 -              Completion_Popup.Text_Area.active_range(text_area) match {
    1.83 -                case Some(range) if range.try_restrict(line_range).isDefined =>
    1.84 -                  paint_completion(range.try_restrict(line_range).get)
    1.85 -                case _ =>
    1.86 -                  for {
    1.87 -                    caret <- caret_range.try_restrict(line_range)
    1.88 -                    names <- rendering.completion_names(caret)
    1.89 -                  } paint_completion(names.range)
    1.90 +            if (!hyperlink_area.is_active && caret_visible) {
    1.91 +              for {
    1.92 +                completion <- Completion_Popup.Text_Area(text_area)
    1.93 +                Text.Info(range, color) <- completion.rendering(rendering, line_range)
    1.94 +                r <- JEdit_Lib.gfx_range(text_area, range)
    1.95 +              } {
    1.96 +                gfx.setColor(color)
    1.97 +                gfx.drawRect(r.x, y + i * line_height, r.length - 1, line_height - 1)
    1.98                }
    1.99              }
   1.100            }
   1.101 @@ -550,7 +533,7 @@
   1.102  
   1.103              val offset = caret - text_area.getLineStartOffset(physical_line)
   1.104              val x = text_area.offsetToXY(physical_line, offset).x
   1.105 -            gfx.setColor(get_caret_color(rendering))
   1.106 +            gfx.setColor(caret_color(rendering))
   1.107              gfx.drawRect(x, y, (metric.unit * metric.average).round.toInt - 1, fm.getHeight - 1)
   1.108            }
   1.109          }