From 2e26fca36b0678ffc1ce09350800a9712970861d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 29 May 2013 11:28:41 -0400 Subject: [PATCH] FIX: Hitting ESC while autocomplete is open shouldn't close the composer. --- .../discourse/components/autocomplete.js | 25 ++++++++----------- .../discourse/views/composer_view.js | 6 ++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/components/autocomplete.js b/app/assets/javascripts/discourse/components/autocomplete.js index 3be4ff53782..8a3485b9f5d 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js +++ b/app/assets/javascripts/discourse/components/autocomplete.js @@ -115,17 +115,14 @@ $.fn.autocomplete = function(options) { }; var renderAutocomplete = function() { - var borderTop, mePos, pos, ul; if (div) { div.hide().remove(); } - if (autocompleteOptions.length === 0) { - return; - } - div = $(options.template({ - options: autocompleteOptions - })); - ul = div.find('ul'); + if (autocompleteOptions.length === 0) return; + + div = $(options.template({ options: autocompleteOptions })); + + var ul = div.find('ul'); selectedOption = 0; markSelected(); ul.find('li').click(function() { @@ -133,7 +130,7 @@ $.fn.autocomplete = function(options) { completeTerm(autocompleteOptions[selectedOption]); return false; }); - pos = null; + var pos = null; if (isInput) { pos = { left: 0, @@ -149,9 +146,9 @@ $.fn.autocomplete = function(options) { left: "-1000px" }); me.parent().append(div); - mePos = me.position(); - borderTop = parseInt(me.css('border-top-width'), 10) || 0; - return div.css({ + var mePos = me.position(); + var borderTop = parseInt(me.css('border-top-width'), 10) || 0; + div.css({ position: 'absolute', top: (mePos.top + pos.top - div.height() + borderTop) + 'px', left: (mePos.left + pos.left + 27) + 'px' @@ -163,9 +160,9 @@ $.fn.autocomplete = function(options) { autocompleteOptions = r; if (!r || r.length === 0) { - return closeAutocomplete(); + closeAutocomplete(); } else { - return renderAutocomplete(); + renderAutocomplete(); } }; diff --git a/app/assets/javascripts/discourse/views/composer_view.js b/app/assets/javascripts/discourse/views/composer_view.js index 376a9895da2..4e1149c6cb3 100644 --- a/app/assets/javascripts/discourse/views/composer_view.js +++ b/app/assets/javascripts/discourse/views/composer_view.js @@ -116,9 +116,13 @@ Discourse.ComposerView = Discourse.View.extend({ // Search for similar topics if the user pauses typing controller.findSimilarTopics(); }, 1000); + }, + keyDown: function(e) { // If the user hit ESC - if (e.which === 27) controller.hitEsc(); + if (e.which === 27) { + this.get('controller').hitEsc(); + } }, didInsertElement: function() {