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 <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
d3c0e95f97
commit
b38eb53e00
2 changed files with 55 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue