From 63e1dac122f4e61395f33741d9a8b254cab6d561 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 25 Jun 2025 18:20:59 +0200 Subject: [PATCH] Fix JS error when `hasFocus` method is overwritten on search index load --- src/renderer/html_handlebars/search.rs | 2 +- tests/gui/search.goml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs index 01ef44ac..942a15b5 100644 --- a/src/renderer/html_handlebars/search.rs +++ b/src/renderer/html_handlebars/search.rs @@ -69,7 +69,7 @@ pub fn create_files( // To reduce the size of the generated JSON by preventing all `"` characters to be // escaped, we instead surround the string with much less common `'` character. format!( - "window.search = JSON.parse('{}');", + "window.search = Object.assign(window.search, JSON.parse('{}'));", index.replace("\\", "\\\\").replace("'", "\\'") ) .as_bytes(), diff --git a/tests/gui/search.goml b/tests/gui/search.goml index a49d9f7b..ae172b43 100644 --- a/tests/gui/search.goml +++ b/tests/gui/search.goml @@ -1,5 +1,6 @@ // This tests basic search behavior. +fail-on-js-error: true go-to: |DOC_PATH| + "index.html" define-function: ( @@ -41,6 +42,9 @@ press-key: 's' wait-for-css-false: ("#search-wrapper", {"display": "none"}) // We ensure the search bar has the focus. assert: "#searchbar:focus" +// Pressing a key will therefore update the search input. +press-key: 't' +assert-text: ("#searchbar", "t") // Now we press `Escape` to ensure that the search input disappears again. press-key: 'Escape'