Fix #3532: Make Enter key accept current tag during autocomplete.
Previously we patched the jqueryui-autocomplete library in order to customize how the Tab and Enter keys behaved. Specifically, we wanted to prevent the Tab key from moving the focus out of the tag input box, and we wanted to prevent the Enter key from submitting the page when editing tags. These things can achieved without patching the library by using `event.preventDefault` and `event.stopImmediatePropagation` to prevent other event handlers from running after these keys trigger the `autocompleteselect` event.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//= require jquery-ui-1.11.2.min.js
|
||||
//= require jquery.hotkeys.js
|
||||
//= require jquery.timeout.js
|
||||
//= require jquery-ui-autocomplete-custom.js
|
||||
//= require jquery-ui-autocomplete-1.11.2.js
|
||||
//= require jquery.storageapi.js
|
||||
//= require jquery.dropdown.min.js
|
||||
//= require jquery.hammer.js
|
||||
|
||||
@@ -59,6 +59,11 @@
|
||||
this.value += after_caret_text;
|
||||
this.selectionStart = this.selectionEnd = original_start;
|
||||
|
||||
// Prevent the enter key from submitting the tag edit form (Danbooru.Upload.initialize_enter_on_tags).
|
||||
event.stopImmediatePropagation();
|
||||
// Prevent the tab key from moving the focus to the next element.
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
},
|
||||
source: function(req, resp) {
|
||||
@@ -114,6 +119,8 @@
|
||||
this.value += after_caret_text;
|
||||
this.selectionStart = this.selectionEnd = original_start;
|
||||
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
return false;
|
||||
},
|
||||
source: function(req, resp) {
|
||||
@@ -217,16 +224,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
$fields_multiple.on("autocompleteselect", function() {
|
||||
Danbooru.autocompleting = true;
|
||||
});
|
||||
|
||||
$fields_multiple.on("autocompleteclose", function() {
|
||||
// this is needed otherwise the var is disabled by the time the
|
||||
// keydown is triggered
|
||||
setTimeout(function() {Danbooru.autocompleting = false;}, 100);
|
||||
});
|
||||
|
||||
$fields_single.autocomplete({
|
||||
minLength: 1,
|
||||
autoFocus: true,
|
||||
|
||||
@@ -66,10 +66,7 @@
|
||||
var $submit = $textarea.parents("form").find('input[type="submit"]');
|
||||
|
||||
$textarea.on("keydown.danbooru.submit", null, "return", function(e) {
|
||||
if (!Danbooru.autocompleting) {
|
||||
$submit.click();
|
||||
}
|
||||
|
||||
$submit.click();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user