FIX: Hitting ESC while autocomplete is open shouldn't close the composer.

This commit is contained in:
Robin Ward 2013-05-29 11:28:41 -04:00
parent 5cb1cc6fcb
commit 2e26fca36b
2 changed files with 16 additions and 15 deletions

View File

@ -115,17 +115,14 @@ $.fn.autocomplete = function(options) {
}; };
var renderAutocomplete = function() { var renderAutocomplete = function() {
var borderTop, mePos, pos, ul;
if (div) { if (div) {
div.hide().remove(); div.hide().remove();
} }
if (autocompleteOptions.length === 0) { if (autocompleteOptions.length === 0) return;
return;
} div = $(options.template({ options: autocompleteOptions }));
div = $(options.template({
options: autocompleteOptions var ul = div.find('ul');
}));
ul = div.find('ul');
selectedOption = 0; selectedOption = 0;
markSelected(); markSelected();
ul.find('li').click(function() { ul.find('li').click(function() {
@ -133,7 +130,7 @@ $.fn.autocomplete = function(options) {
completeTerm(autocompleteOptions[selectedOption]); completeTerm(autocompleteOptions[selectedOption]);
return false; return false;
}); });
pos = null; var pos = null;
if (isInput) { if (isInput) {
pos = { pos = {
left: 0, left: 0,
@ -149,9 +146,9 @@ $.fn.autocomplete = function(options) {
left: "-1000px" left: "-1000px"
}); });
me.parent().append(div); me.parent().append(div);
mePos = me.position(); var mePos = me.position();
borderTop = parseInt(me.css('border-top-width'), 10) || 0; var borderTop = parseInt(me.css('border-top-width'), 10) || 0;
return div.css({ div.css({
position: 'absolute', position: 'absolute',
top: (mePos.top + pos.top - div.height() + borderTop) + 'px', top: (mePos.top + pos.top - div.height() + borderTop) + 'px',
left: (mePos.left + pos.left + 27) + 'px' left: (mePos.left + pos.left + 27) + 'px'
@ -163,9 +160,9 @@ $.fn.autocomplete = function(options) {
autocompleteOptions = r; autocompleteOptions = r;
if (!r || r.length === 0) { if (!r || r.length === 0) {
return closeAutocomplete(); closeAutocomplete();
} else { } else {
return renderAutocomplete(); renderAutocomplete();
} }
}; };

View File

@ -116,9 +116,13 @@ Discourse.ComposerView = Discourse.View.extend({
// Search for similar topics if the user pauses typing // Search for similar topics if the user pauses typing
controller.findSimilarTopics(); controller.findSimilarTopics();
}, 1000); }, 1000);
},
keyDown: function(e) {
// If the user hit ESC // If the user hit ESC
if (e.which === 27) controller.hitEsc(); if (e.which === 27) {
this.get('controller').hitEsc();
}
}, },
didInsertElement: function() { didInsertElement: function() {