Replace word with suggestion and learn word

This commit is contained in:
Alasdair Smith 2018-05-04 15:30:06 +01:00
parent cf123ce857
commit 034531d323
3 changed files with 27 additions and 6 deletions

View file

@ -4,7 +4,7 @@ define ["base"], (App) ->
open: "<" open: "<"
top: "<" top: "<"
left: "<" left: "<"
suggestions: "<" highlight: "<"
replaceWord: "&" replaceWord: "&"
learnWord: "&" learnWord: "&"
} }
@ -16,12 +16,17 @@ define ["base"], (App) ->
ng-class="{open: $ctrl.open}" ng-class="{open: $ctrl.open}"
> >
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li ng-repeat="suggestion in $ctrl.suggestions | limitTo:8"> <li ng-repeat="suggestion in $ctrl.highlight.suggestions | limitTo:8">
<a href ng-click="$ctrl.replaceWord(suggestion)">{{ suggestion }}</a> <a
href
ng-click="$ctrl.replaceWord({ highlight: $ctrl.highlight, suggestion: suggestion })"
>
{{ suggestion }}
</a>
</li> </li>
<li class="divider"></li> <li class="divider"></li>
<li> <li>
<a href ng-click="$ctrl.learnWord(suggestion)">Add to Dictionary</a> <a href ng-click="$ctrl.learnWord({ highlight: $ctrl.highlight })">Add to Dictionary</a>
</li> </li>
</ul> </ul>
</div> </div>

View file

@ -514,7 +514,9 @@ define [
open="spellMenu.open" open="spellMenu.open"
top="spellMenu.top" top="spellMenu.top"
left="spellMenu.left" left="spellMenu.left"
suggestions="spellMenu.suggestions" highlight="spellMenu.highlight"
replace-word="replaceWord(highlight, suggestion)"
learn-word="learnWord(highlight)"
></spell-menu> ></spell-menu>
<div <div
class="annotation-label" class="annotation-label"
@ -624,3 +626,8 @@ define [
highlight.row, highlight.column + highlight.word.length highlight.row, highlight.column + highlight.word.length
) )
) )
replaceWord: (highlight, newWord) =>
@editor.getSession().replace(new Range(
highlight.row, highlight.column,
highlight.row, highlight.column + highlight.word.length
), newWord)

View file

@ -14,6 +14,9 @@ define [], () ->
if language != oldLanguage and oldLanguage? if language != oldLanguage and oldLanguage?
@runFullCheck() @runFullCheck()
@$scope.replaceWord = @adapter.replaceWord
@$scope.learnWord = @learnWord
init: () -> init: () ->
@updatedLines = Array(@adapter.getLines().length).fill(true) @updatedLines = Array(@adapter.getLines().length).fill(true)
@runSpellCheckSoon(200) if @isSpellCheckEnabled() @runSpellCheckSoon(200) if @isSpellCheckEnabled()
@ -53,7 +56,7 @@ define [], () ->
open: true open: true
top: coords.y + 'px' top: coords.y + 'px'
left: coords.x + 'px' left: coords.x + 'px'
suggestions: highlight.suggestions highlight: highlight
} }
@setUpClickOffContextMenuListener() @setUpClickOffContextMenuListener()
return false return false
@ -70,6 +73,12 @@ define [], () ->
@$scope.$apply () => @$scope.$apply () =>
@$scope.spellMenu.open = false @$scope.spellMenu.open = false
learnWord: (highlight) =>
@apiRequest "/learn", word: highlight.word
@adapter.wordManager.removeHighlight highlight
language = @$scope.spellCheckLanguage
@cache?.put("#{language}:#{highlight.word}", true)
runFullCheck: () -> runFullCheck: () ->
@adapter.wordManager.reset() @adapter.wordManager.reset()
@runSpellCheck() if @isSpellCheckEnabled() @runSpellCheck() if @isSpellCheckEnabled()