src/Tools/jEdit/src/completion_popup.scala
changeset 56564 94c55cc73747
parent 56326 c3d7b3bb2708
child 56565 927dff80d0df
     1.1 --- a/src/Tools/jEdit/src/completion_popup.scala	Sun Apr 13 19:55:16 2014 +0200
     1.2 +++ b/src/Tools/jEdit/src/completion_popup.scala	Sun Apr 13 21:43:25 2014 +0200
     1.3 @@ -188,6 +188,41 @@
     1.4      }
     1.5  
     1.6  
     1.7 +    /* spell-checker completion */
     1.8 +
     1.9 +    def spell_checker_completion(rendering: Rendering): Option[Completion.Result] =
    1.10 +    {
    1.11 +      PIDE.spell_checker.get match {
    1.12 +        case Some(spell_checker) =>
    1.13 +          val caret_range = before_caret_range(rendering)
    1.14 +
    1.15 +          val result =
    1.16 +            for {
    1.17 +              spell_range <- rendering.spell_checker_point(caret_range)
    1.18 +              text <- JEdit_Lib.try_get_text(text_area.getBuffer, spell_range)
    1.19 +              caret_range0 = caret_range - spell_range.start
    1.20 +              Text.Info(range0, word) <-
    1.21 +                Spell_Checker.marked_words(text,
    1.22 +                  info => info.range.overlaps(caret_range0)).headOption
    1.23 +            } yield Text.Info(range0 + spell_range.start, word)
    1.24 +
    1.25 +          result match {
    1.26 +            case Some(Text.Info(range, original)) =>
    1.27 +              val words = spell_checker.complete(original)
    1.28 +              if (words.isEmpty) None
    1.29 +              else {
    1.30 +                val descr = "(from dictionary " + quote(spell_checker.toString) + ")"
    1.31 +                val items = words.map(word =>
    1.32 +                  Completion.Item(range, original, "", List(word, descr), word, 0, false))
    1.33 +                Some(Completion.Result(range, original, false, items))
    1.34 +              }
    1.35 +            case None => None
    1.36 +          }
    1.37 +        case None => None
    1.38 +      }
    1.39 +    }
    1.40 +
    1.41 +
    1.42      /* completion action: text area */
    1.43  
    1.44      private def insert(item: Completion.Item)
    1.45 @@ -318,9 +353,15 @@
    1.46          }
    1.47          if (no_completion) false
    1.48          else {
    1.49 -          val result =
    1.50 +          val result0 =
    1.51              Completion.Result.merge(history,
    1.52                semantic_completion, syntax_completion(history, explicit, opt_rendering))
    1.53 +          val result =
    1.54 +            opt_rendering match {
    1.55 +              case None => result0
    1.56 +              case Some(rendering) =>
    1.57 +                Completion.Result.merge(history, result0, spell_checker_completion(rendering))
    1.58 +            }
    1.59  
    1.60            result match {
    1.61              case Some(result) =>