src/Tools/jEdit/src/completion_popup.scala
changeset 55692 19e8b00684f7
parent 55690 d73949233c2e
child 55693 93ba0085e888
     1.1 --- a/src/Tools/jEdit/src/completion_popup.scala	Sun Feb 23 18:18:40 2014 +0100
     1.2 +++ b/src/Tools/jEdit/src/completion_popup.scala	Sun Feb 23 19:29:27 2014 +0100
     1.3 @@ -79,16 +79,14 @@
     1.4        Swing_Thread.require()
     1.5  
     1.6        val buffer = text_area.getBuffer
     1.7 -      val len = item.original.length
     1.8 -      if (buffer.isEditable && len > 0) {
     1.9 +      val range = item.range
    1.10 +      if (buffer.isEditable && range.length > 0) {
    1.11          JEdit_Lib.buffer_edit(buffer) {
    1.12 -          val caret = text_area.getCaretPosition
    1.13 -          JEdit_Lib.try_get_text(buffer, Text.Range(caret - len, caret)) match {
    1.14 +          JEdit_Lib.try_get_text(buffer, range) match {
    1.15              case Some(text) if text == item.original =>
    1.16 -              buffer.remove(caret - len, len)
    1.17 -              buffer.insert(caret - len, item.replacement)
    1.18 -              if (item.move != 0)
    1.19 -                text_area.moveCaretPosition(text_area.getCaretPosition + item.move)
    1.20 +              buffer.remove(range.start, range.length)
    1.21 +              buffer.insert(range.start, item.replacement)
    1.22 +              text_area.moveCaretPosition(range.start + item.replacement.length + item.move)
    1.23              case _ =>
    1.24            }
    1.25          }
    1.26 @@ -120,7 +118,7 @@
    1.27                    rendering.completion_context(JEdit_Lib.stretch_point_range(buffer, caret))
    1.28                }) getOrElse syntax.completion_context
    1.29  
    1.30 -            syntax.completion.complete(history, decode, explicit, text, context) match {
    1.31 +            syntax.completion.complete(history, decode, explicit, start, text, context) match {
    1.32                case Some(result) =>
    1.33                  if (result.unique && result.items.head.immediate && immediate)
    1.34                    insert(result.items.head)
    1.35 @@ -259,17 +257,16 @@
    1.36      {
    1.37        Swing_Thread.require()
    1.38  
    1.39 -      val len = item.original.length
    1.40 -      if (text_field.isEditable && len > 0) {
    1.41 -        val caret = text_field.getCaret.getDot
    1.42 +      val range = item.range
    1.43 +      if (text_field.isEditable && range.length > 0) {
    1.44          val content = text_field.getText
    1.45 -        JEdit_Lib.try_get_text(content, Text.Range(caret - len, caret)) match {
    1.46 +        JEdit_Lib.try_get_text(content, range) match {
    1.47            case Some(text) if text == item.original =>
    1.48              text_field.setText(
    1.49 -              content.substring(0, caret - len) +
    1.50 +              content.substring(0, range.start) +
    1.51                item.replacement +
    1.52 -              content.substring(caret))
    1.53 -            text_field.getCaret.setDot(caret - len + item.replacement.length + item.move)
    1.54 +              content.substring(range.stop))
    1.55 +            text_field.getCaret.setDot(range.start + item.replacement.length + item.move)
    1.56            case _ =>
    1.57          }
    1.58        }
    1.59 @@ -288,7 +285,7 @@
    1.60            val text = text_field.getText.substring(0, caret)
    1.61  
    1.62            syntax.completion.complete(
    1.63 -              history, decode = true, explicit = false, text, syntax.completion_context) match {
    1.64 +              history, decode = true, explicit = false, 0, text, syntax.completion_context) match {
    1.65              case Some(result) =>
    1.66                val fm = text_field.getFontMetrics(text_field.getFont)
    1.67                val loc =