From 034531d3234a78380c835ff0c3e45f1567899f77 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Fri, 4 May 2018 15:30:06 +0100 Subject: [PATCH] Replace word with suggestion and learn word --- .../coffee/ide/editor/components/spellMenu.coffee | 13 +++++++++---- .../coffee/ide/editor/directives/aceEditor.coffee | 9 ++++++++- .../aceEditor/spell-check/SpellCheckManager.coffee | 11 ++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/services/web/public/coffee/ide/editor/components/spellMenu.coffee b/services/web/public/coffee/ide/editor/components/spellMenu.coffee index c3fd78efba..ff3462e03e 100644 --- a/services/web/public/coffee/ide/editor/components/spellMenu.coffee +++ b/services/web/public/coffee/ide/editor/components/spellMenu.coffee @@ -4,7 +4,7 @@ define ["base"], (App) -> open: "<" top: "<" left: "<" - suggestions: "<" + highlight: "<" replaceWord: "&" learnWord: "&" } @@ -16,12 +16,17 @@ define ["base"], (App) -> ng-class="{open: $ctrl.open}" > diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index a30b93aaa0..34ffedcac8 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -514,7 +514,9 @@ define [ open="spellMenu.open" top="spellMenu.top" left="spellMenu.left" - suggestions="spellMenu.suggestions" + highlight="spellMenu.highlight" + replace-word="replaceWord(highlight, suggestion)" + learn-word="learnWord(highlight)" >
+ @editor.getSession().replace(new Range( + highlight.row, highlight.column, + highlight.row, highlight.column + highlight.word.length + ), newWord) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee index c6b40c7b77..3d274abea4 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee @@ -14,6 +14,9 @@ define [], () -> if language != oldLanguage and oldLanguage? @runFullCheck() + @$scope.replaceWord = @adapter.replaceWord + @$scope.learnWord = @learnWord + init: () -> @updatedLines = Array(@adapter.getLines().length).fill(true) @runSpellCheckSoon(200) if @isSpellCheckEnabled() @@ -53,7 +56,7 @@ define [], () -> open: true top: coords.y + 'px' left: coords.x + 'px' - suggestions: highlight.suggestions + highlight: highlight } @setUpClickOffContextMenuListener() return false @@ -70,6 +73,12 @@ define [], () -> @$scope.$apply () => @$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: () -> @adapter.wordManager.reset() @runSpellCheck() if @isSpellCheckEnabled()