106 case Some(result) => |
106 case Some(result) => |
107 result.items.map(item => |
107 result.items.map(item => |
108 Protocol.CompletionItem( |
108 Protocol.CompletionItem( |
109 label = item.replacement, |
109 label = item.replacement, |
110 detail = Some(item.description.mkString(" ")), |
110 detail = Some(item.description.mkString(" ")), |
111 range = Some(doc.range(item.range)))) |
111 range = Some(doc.range(item.range)))) ::: |
|
112 spell_checker_menu(caret) |
112 } |
113 } |
113 } |
114 } |
114 } |
115 } |
115 } |
116 } |
116 |
117 |
206 } |
207 } |
207 |
208 |
208 def spell_checker_completion(caret: Text.Offset): Option[Completion.Result] = |
209 def spell_checker_completion(caret: Text.Offset): Option[Completion.Result] = |
209 model.resources.spell_checker.get.flatMap(_.completion(rendering, caret)) |
210 model.resources.spell_checker.get.flatMap(_.completion(rendering, caret)) |
210 |
211 |
|
212 def spell_checker_menu(caret: Text.Offset): List[Protocol.CompletionItem] = |
|
213 { |
|
214 val result = |
|
215 for { |
|
216 spell_checker <- model.resources.spell_checker.get |
|
217 range = before_caret_range(caret) |
|
218 Text.Info(_, word) <- Spell_Checker.current_word(rendering, range) |
|
219 } yield (spell_checker, word) |
|
220 |
|
221 result match { |
|
222 case Some((spell_checker, word)) => |
|
223 |
|
224 def item(command: Protocol.Command): Protocol.CompletionItem = |
|
225 Protocol.CompletionItem( |
|
226 label = command.title, |
|
227 insertText = Some(""), |
|
228 range = Some(model.content.doc.range(Text.Range(caret))), |
|
229 command = Some(command)) |
|
230 |
|
231 val update_items = |
|
232 if (spell_checker.check(word)) |
|
233 List( |
|
234 item(Protocol.Exclude_Word.command), |
|
235 item(Protocol.Exclude_Word_Permanently.command)) |
|
236 else |
|
237 List( |
|
238 item(Protocol.Include_Word.command), |
|
239 item(Protocol.Include_Word_Permanently.command)) |
|
240 |
|
241 val reset_items = |
|
242 spell_checker.reset_enabled() match { |
|
243 case 0 => Nil |
|
244 case n => |
|
245 val command = Protocol.Reset_Words.command |
|
246 List(item(command).copy(label = command.title + " (" + n + ")")) |
|
247 } |
|
248 |
|
249 update_items ::: reset_items |
|
250 |
|
251 case None => Nil |
|
252 } |
|
253 } |
|
254 |
211 |
255 |
212 /* decorations */ |
256 /* decorations */ |
213 |
257 |
214 def decorations: List[Document_Model.Decoration] = // list of canonical length and order |
258 def decorations: List[Document_Model.Decoration] = // list of canonical length and order |
215 Par_List.map((f: () => List[Document_Model.Decoration]) => f(), |
259 Par_List.map((f: () => List[Document_Model.Decoration]) => f(), |