From 18e8bc686fc5dc5a1b42953152c37f91c2e0fb22 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Sat, 23 Nov 2024 12:40:28 -0500 Subject: [PATCH] Trim search query strings --- ext/js/display/query-parser.js | 9 +++++---- ext/js/display/search-display-controller.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index cf487a3d35..a85ccc4a94 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -304,13 +304,14 @@ export class QueryParser extends EventDispatcher { termNode.className = 'query-parser-term'; termNode.dataset.offset = `${offset}`; for (const {text, reading} of term) { + const trimmedText = text.trim(); if (reading.length === 0) { - termNode.appendChild(document.createTextNode(text)); + termNode.appendChild(document.createTextNode(trimmedText)); } else { - const reading2 = this._convertReading(text, reading); - termNode.appendChild(this._createSegment(text, reading2, offset)); + const reading2 = this._convertReading(trimmedText, reading); + termNode.appendChild(this._createSegment(trimmedText, reading2, offset)); } - offset += text.length; + offset += trimmedText.length; } fragment.appendChild(termNode); } diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 50175cb9e6..e24a2cfe0f 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -237,7 +237,7 @@ export class SearchDisplayController { this._searchBackButton.hidden = !showBackButton; if (this._queryInput.value !== query) { - this._queryInput.value = query; + this._queryInput.value = query.trim(); this._updateSearchHeight(true); } this._setIntroVisible(!valid, animate);