From e4ff641c9a498c50e657561a7e59a1c289662a09 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Mon, 17 Feb 2020 23:56:13 +0000 Subject: [PATCH] Fix autocomplete insert completion It was removing line returns, even when line returns are important, such as in the blacklist and frequent tags input fields. Besides those, it was also causing confusion when editing tags on a post, as those are divided into categories, but adding an additional tag for a category at the end of a group causes groups of tags to be combined. --- app/javascript/src/javascripts/autocomplete.js.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/javascript/src/javascripts/autocomplete.js.erb b/app/javascript/src/javascripts/autocomplete.js.erb index 767955f2c..233ef9889 100644 --- a/app/javascript/src/javascripts/autocomplete.js.erb +++ b/app/javascript/src/javascripts/autocomplete.js.erb @@ -177,8 +177,9 @@ Autocomplete.parse_query = function(text, caret) { // Update the input field with the item currently focused in the // autocomplete menu, then position the caret just after the inserted completion. Autocomplete.insert_completion = function(input, completion) { - var before_caret_text = input.value.substring(0, input.selectionStart).trim(); - var after_caret_text = input.value.substring(input.selectionStart).trim(); + // Trim all whitespace (tabs, spaces) except for line returns + var before_caret_text = input.value.substring(0, input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, ""); + var after_caret_text = input.value.substring(input.selectionStart).replace(/^[ \t]+|[ \t]+$/gm, ""); var regexp = new RegExp("(" + Autocomplete.TAG_PREFIXES + ")?\\S+$", "g"); before_caret_text = before_caret_text.replace(regexp, "$1") + completion + " ";