Skip to content

Commit

Permalink
Fix Enter sending comment instead of adding autocomplete item to message
Browse files Browse the repository at this point in the history
When the autocomplete popover is shown the At.js plugin listens on the
message input field for key down events, and when Enter is pressed it
adds the selected item to the message. However, as "_onTypeComment" also
handles key down events for the message input field, when Enter was
pressed the comment was submitted and At.js had no chance to add the
item before that happened. Now when Enter is pressed and the
autocomplete popover is shown the comment is not submitted, and thus
At.js adds the selected item to the message as expected.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Dec 7, 2017
1 parent c43f64d commit 703eb69
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/comments/js/commentstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,11 @@
$field.toggleClass('error', limitExceeded);
$submitButton.prop('disabled', limitExceeded);

// Submits form with Enter, but Shift+Enter is a new line
if (ev.keyCode === 13 && !ev.shiftKey) {
// Submits form with Enter, but Shift+Enter is a new line. If the
// autocomplete popover is being shown Enter does not submit the
// form either; it will be handled by At.js which will add the
// currently selected item to the message.
if (ev.keyCode === 13 && !ev.shiftKey && !$field.atwho('isSelecting')) {
$submitButton.click();
ev.preventDefault();
}
Expand Down

0 comments on commit 703eb69

Please sign in to comment.