Compare commits

..

3 commits

3 changed files with 36 additions and 34 deletions

View file

@ -14,7 +14,7 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace = false
[*.{nix,yml,yaml}]
[*.{js,nix,yml,yaml}]
indent_style = space
indent_size = 2
tab_width = 2

View file

@ -1,39 +1,40 @@
document.addEventListener("DOMContentLoaded", () => {
// The search widget should only be visible if we're in the options page. Else, we
// want it hidden.
if (window.location.pathname.endsWith("options.html")) {
const searchBar = document.createElement("div");
searchBar.id = "search-bar";
searchBar.innerHTML = `
<input type="text" id="search-input" placeholder="Search options by ID..." />
<div id="search-results"></div>
`;
if (!window.location.pathname.endsWith("options.html")) return;
document.body.prepend(searchBar);
const searchBar = document.createDocumentFragment();
const searchDiv = document.createElement("div");
searchDiv.id = "search-bar";
searchDiv.innerHTML = `
<input type="text" id="search-input" placeholder="Search options by ID..." />
<div id="search-results"></div>
`;
searchBar.appendChild(searchDiv);
document.body.prepend(searchDiv);
const dtElements = document.querySelectorAll("dt");
const ddElements = document.querySelectorAll("dd");
const dtElements = Array.from(document.querySelectorAll("dt"));
const ddElements = Array.from(document.querySelectorAll("dd"));
const dtOptionIds = dtElements.map(
(dt) => dt.querySelector("a")?.id.toLowerCase() || "",
);
if (dtElements.length === 0 || ddElements.length === 0) {
console.warn(
"No <dt> or <dd> elements found. Ensure your HTML contains the correct structure.",
);
}
if (dtElements.length === 0 || ddElements.length === 0) {
console.warn("Something went wrong, page may be loaded incorrectly.");
return;
}
// handle input and filter visible options
document
.getElementById("search-input")
.addEventListener("input", (event) => {
const query = event.target.value.toLowerCase();
dtElements.forEach((dt, index) => {
const optionId =
dt.querySelector("a")?.id.toLowerCase() || "";
const isMatch = optionId.includes(query);
let debounceTimeout;
document.getElementById("search-input").addEventListener("input", (event) => {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
const query = event.target.value.toLowerCase();
dtElements.forEach((dt, index) => {
const isMatch = dtOptionIds[index].includes(query);
// toggle visibility based on the query match
dt.classList.toggle("hidden", !isMatch);
ddElements[index]?.classList.toggle("hidden", !isMatch);
});
});
}
if (dt.classList.contains("hidden") !== !isMatch) {
dt.classList.toggle("hidden", !isMatch);
ddElements[index]?.classList.toggle("hidden", !isMatch);
}
});
}, 200);
});
});

View file

@ -6,6 +6,7 @@
inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) int bool str nullOr either listOf attrsOf;
inherit (lib.nvim.types) mkPluginSetupOption;
cfg = config.vim.visuals;
in {
@ -15,7 +16,7 @@ in {
options.vim.visuals.indent-blankline = {
enable = mkEnableOption "indentation guides [indent-blankline]";
setupOpts = {
setupOpts = mkPluginSetupOption "indent-blankline" {
debounce = mkOption {
type = int;
description = "Debounce time in milliseconds";