From dbd7b9582377967d205263e68d0c39d910f6fab5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 28 Nov 2014 13:27:25 +0000 Subject: [PATCH] Close spell check menu on scroll so it doesn't appear in the wrong position --- .../spell-check/SpellCheckManager.coffee | 6 ++ .../spell-check/SpellingMenuView.coffee | 82 ------------------- 2 files changed, 6 insertions(+), 82 deletions(-) delete mode 100644 services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellingMenuView.coffee 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 8b73ce6df9..bdddb2ab20 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 @@ -17,12 +17,18 @@ define [ onChange = (e) => @runCheckOnChange(e) + + onScroll = () => + @closeContextMenu() @editor.on "changeSession", (e) => @runSpellCheckSoon(200) e.oldSession?.getDocument().off "change", onChange e.session.getDocument().on "change", onChange + + e.oldSession?.off "changeScrollTop", onScroll + e.session.on "changeScrollTop", onScroll @$scope.spellingMenu = {left: '0px', top: '0px'} diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellingMenuView.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellingMenuView.coffee deleted file mode 100644 index 3ba9fd1d96..0000000000 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellingMenuView.coffee +++ /dev/null @@ -1,82 +0,0 @@ -define [ - "libs/backbone" - "libs/mustache" -], () -> - SUGGESTIONS_TO_SHOW = 5 - - SpellingMenuView = Backbone.View.extend - templates: - menu: $("#spellingMenuTemplate").html() - entry: $("#spellingMenuEntryTemplate").html() - - events: - "click a#learnWord": -> - @trigger "click:learn", @_currentHighlight - @hide() - - initialize: (options) -> - @ide = options.ide - @ide.editor.getContainerElement().append @render().el - @ide.editor.on "click", () => @hide() - @ide.editor.on "scroll", () => @hide() - @ide.editor.on "update:doc", () => @hide() - @ide.editor.on "change:doc", () => @hide() - - render: () -> - @setElement($(@templates.menu)) - @$el.css "z-index" : 10000 - @$(".dropdown-toggle").dropdown() - @hide() - return @ - - showForHighlight: (highlight) -> - if @_currentHighlight? and highlight != @_currentHighlight - @_close() - - if !@_currentHighlight? - @_currentHighlight = highlight - @_setSuggestions(highlight) - position = @ide.editor.textToEditorCoordinates( - highlight.row - highlight.column + highlight.word.length - ) - @_position(position.x, position.y) - @_show() - - hideIfAppropriate: (cursorPosition) -> - if @_currentHighlight? - if !@_cursorCloseToHighlight(cursorPosition, @_currentHighlight) and !@_isOpen() - @hide() - - hide: () -> - delete @_currentHighlight - @_close() - @$el.hide() - - _setSuggestions: (highlight) -> - @$(".spelling-suggestion").remove() - divider = @$(".divider") - for suggestion in highlight.suggestions.slice(0, SUGGESTIONS_TO_SHOW) - do (suggestion) => - entry = $(Mustache.to_html(@templates.entry, word: suggestion)) - divider.before(entry) - entry.on "click", () => - @trigger "click:suggestion", suggestion, highlight - - _show: () -> @$el.show() - - _isOpen: () -> - @$(".dropdown-menu").is(":visible") - - _close: () -> - if @_isOpen() - @$el.dropdown("toggle") - - _cursorCloseToHighlight: (position, highlight) -> - position.row == highlight.row and - position.column >= highlight.column and - position.column <= highlight.column + highlight.word.length + 1 - - _position: (x,y) -> @$el.css left: x, top: y - -