From b38eb53e003bee6afa377dce50a71b75287b2647 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 21 Nov 2022 13:29:18 +0100 Subject: [PATCH] doc: extensions: kconfig: allow to copy link to results This patch allows copying a URL to the current Kconfig search results. For example, I can now share the search results for "CONFIG_TEST.*". A new button is added to the search box that, when clicked, copies to the clipboard the URL. This feature is achieved by prepending query hashes with '!'. When '!' is found, the content of the URL hash is left intact, whereas before it was always enclosed within '^$' to produce an exact match. Signed-off-by: Gerard Marull-Paretas --- .../zephyr/kconfig/static/kconfig.css | 29 +++++++++++++++-- .../zephyr/kconfig/static/kconfig.mjs | 32 +++++++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/doc/_extensions/zephyr/kconfig/static/kconfig.css b/doc/_extensions/zephyr/kconfig/static/kconfig.css index f5a1d165307..d66cb559b96 100644 --- a/doc/_extensions/zephyr/kconfig/static/kconfig.css +++ b/doc/_extensions/zephyr/kconfig/static/kconfig.css @@ -5,14 +5,37 @@ /* Kconfig search */ -#__kconfig-search input { +#__kconfig-search .input-container { border-radius: 5px; border: 1px solid rgba(149, 157, 165, 0.2); box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px !important; - font-size: 18px; margin-bottom: 0.5rem; - padding: 0.75rem; width: 100%; + height: 60px; +} + +#__kconfig-search .input-container input { + font-size: 18px; + width: 90%; + height: 100%; + padding: 0.75rem; + border: none; + box-shadow: none !important; + background-color: white; +} + +#__kconfig-search .input-container input:focus, +#__kconfig-search .input-container input:active { + outline: none; +} + +#__kconfig-search .input-container button { + font-size: 22px; + float: right; + width: 10%; + height: 100%; + border: none; + background-color: white; } #__kconfig-search select { diff --git a/doc/_extensions/zephyr/kconfig/static/kconfig.mjs b/doc/_extensions/zephyr/kconfig/static/kconfig.mjs index 0875d52b729..ae27532ab6a 100644 --- a/doc/_extensions/zephyr/kconfig/static/kconfig.mjs +++ b/doc/_extensions/zephyr/kconfig/static/kconfig.mjs @@ -344,8 +344,12 @@ function doSearchFromURL() { return; } - const option = rawOption.replace(/[^A-Za-z0-9_]+/g, ''); - input.value = '^' + option + '$'; + const option = decodeURIComponent(rawOption); + if (option.startsWith('!')) { + input.value = option.substring(1); + } else { + input.value = '^' + option + '$'; + } searchOffset = 0; doSearch(); @@ -360,10 +364,32 @@ function setupKconfigSearch() { } /* create input field */ + const inputContainer = document.createElement('div'); + inputContainer.className = 'input-container' + container.appendChild(inputContainer) + input = document.createElement('input'); input.placeholder = 'Type a Kconfig option name (RegEx allowed)'; input.type = 'text'; - container.appendChild(input); + inputContainer.appendChild(input); + + const copyLinkButton = document.createElement('button'); + copyLinkButton.title = "Copy link to results"; + copyLinkButton.onclick = () => { + if (!window.isSecureContext) { + console.error("Cannot copy outside of a secure context"); + return; + } + + const copyURL = window.location.protocol + '//' + window.location.host + + window.location.pathname + '#!' + input.value; + + navigator.clipboard.writeText(encodeURI(copyURL)); + } + inputContainer.appendChild(copyLinkButton) + + const copyLinkText = document.createTextNode('🔗'); + copyLinkButton.appendChild(copyLinkText); /* create search tools container */ searchTools = document.createElement('div');