Browse Source

Fix tag autocompletion when space between tags

Previously, typing a space at the start of a tag would prevent the
autocomplete options from appearing.
merge-requests/104/merge
Shahzaib Sahibzada 5 years ago
committed by Deimos
parent
commit
d901abfb84
  1. 9
      tildes/static/js/behaviors/autocomplete-input.js

9
tildes/static/js/behaviors/autocomplete-input.js

@ -163,7 +163,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
if ($autocompleteMenu) {
$autocompleteMenu.remove();
}
if ($this.val() === "") {
if ($this.val().trim() === "") {
return;
}
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
@ -171,7 +171,12 @@ $.onmount("[data-js-autocomplete-input]", function() {
.data("js-autocomplete-input")
.filter(function(suggestion) {
return (
suggestion.startsWith($this.val().toLowerCase()) &&
suggestion.startsWith(
$this
.val()
.toLowerCase()
.trim()
) &&
!$tagsHiddenInput
.val()
.match(new RegExp("(^|,)" + suggestion + ","))

Loading…
Cancel
Save