diff options
Diffstat (limited to 'client/components/main')
-rw-r--r-- | client/components/main/editor.js (renamed from client/components/main/rendered.js) | 32 | ||||
-rw-r--r-- | client/components/main/events.js | 8 | ||||
-rw-r--r-- | client/components/main/templates.html | 2 |
3 files changed, 30 insertions, 12 deletions
diff --git a/client/components/main/rendered.js b/client/components/main/editor.js index 787e8225..95a8dc5d 100644 --- a/client/components/main/rendered.js +++ b/client/components/main/editor.js @@ -1,5 +1,9 @@ -Template.editor.rendered = function() { - this.$('textarea').textcomplete([ +var dropdownMenuIsOpened = false; + +Template.editor.onRendered(function() { + var $textarea = this.$('textarea'); + + $textarea.textcomplete([ // Emojies { match: /\B:([\-+\w]*)$/, @@ -37,4 +41,26 @@ Template.editor.rendered = function() { index: 1 } ]); -}; + + // Since commit d474017 jquery-textComplete automatically closes a potential + // opened dropdown menu when the user press Escape. This behavior conflicts + // with our EscapeActions system, but it's too complicated and hacky to + // monkey-pach textComplete to disable it -- I tried. Instead we listen to + // 'open' and 'hide' events, and create a ghost escapeAction when the dropdown + // is opened (and rely on textComplete to execute the actual action). + $textarea.on({ + 'textComplete:show': function() { + dropdownMenuIsOpened = true; + }, + 'textComplete:hide': function() { + Tracker.afterFlush(function() { + dropdownMenuIsOpened = false; + }); + } + }); +}); + +EscapeActions.register(10, + function() { return dropdownMenuIsOpened; }, + function() {} +); diff --git a/client/components/main/events.js b/client/components/main/events.js deleted file mode 100644 index beb90c5e..00000000 --- a/client/components/main/events.js +++ /dev/null @@ -1,8 +0,0 @@ -Template.editor.events({ - // Pressing Ctrl+Enter should submit the form. - 'keydown textarea': function(event) { - if (event.keyCode === 13 && (event.metaKey || event.ctrlKey)) { - $(event.currentTarget).parents('form:first').submit(); - } - } -}); diff --git a/client/components/main/templates.html b/client/components/main/templates.html index e9be0f93..4828663a 100644 --- a/client/components/main/templates.html +++ b/client/components/main/templates.html @@ -12,7 +12,7 @@ </template> <template name="editor"> - <textarea class="{{class}}" placeholder="{{_ 'comment-placeholder'}}" id="{{id}}" tabindex="1">{{> UI.contentBlock }}</textarea> + <textarea class="{{class}}" placeholder="{{_ 'comment-placeholder'}}" id="{{id}}" autofocus="{{autofocus}}">{{> UI.contentBlock}}</textarea> </template> <template name="viewer">{{#markdown}}{{#emoji}}{{#mentions}}{{> UI.contentBlock }}{{/mentions}}{{/emoji}}{{/markdown}}</template> |