Files
OneCAD-Draft/help/assets/js/help.js
T
Felix RiestraandClaude Sonnet 5 7cddf31bcb Add named parameters, UI scale setting, OPTIONS/OP dispatch, and help manual
Named parameters (docs/named_parameters_design.md, stages 3-4):
- ParameterTable (src/scene/named_parameters.rs): a document-wide table of
  named formulas, each resolved through a shared expression evaluator with
  cross-parameter references, cycle detection, and division-by-zero/parse
  error reporting. SketchConstraint::driving_param becomes DrivingValue
  (Literal | Named) instead of a bare f64, resolved at solve time by
  sketch_solve::build_constraint via Scene::named_parameters.
- Persistence (src/scene/named_parameters_persist.rs): same lazy XRecord
  model sketch_persist.rs already established, synced around open/save.
  Bumps the sketch-constraint XRecord's own format version (1 -> 2) since
  DrivingValue's shape doesn't line up with a version-1 blob's bytes.
- PARAMETERS command and its editor (src/ui/window/named_parameters.rs):
  add/remove/edit rows, live validation, duplicate-name detection: Apply
  defines the table and re-solves every constraint scope with a
  named-parameter-driven constraint (command_driver.rs). Distance/Angle
  constraint prompts (modules/draw/constrain/value.rs) now accept either a
  literal or an existing parameter's name, mirroring how the constraint's
  own value prompt already worked.
- Undo scope-down carried over from this project's own established pattern
  (constraint-system stage 9): the geometry an Apply moves is one undo
  step, but the parameter table edit itself has no undo entry yet — a
  documented follow-up, not a silent gap.

UI scale setting (src/app/settings.rs, app/mod.rs, ui/window/options.rs):
  a whole-interface scale percentage (50-200%), wired directly into iced's
  own per-window scale_factor hook rather than per-panel font-size
  plumbing, so it applies immediately to every panel, dialog, and the
  ribbon at once. Persisted alongside the existing lineweight-display-scale
  setting.

OPTIONS/OP command dispatch (app/commands/view.rs, app/commands/mod.rs):
  OPTIONS was registered for autocomplete but had no dispatch arm — the
  Start-tab welcome screen's own button was the only way to reach it.
  Found live-testing the UI-scale setting, unrelated to that feature
  itself. "OP" is AutoCAD's own short alias.

help/: a new self-contained static user-help manual (manual.md as the
authored source, tools/build_help.py splits it into the committed static
HTML pages plus search index) — not yet wired into the application.

64 new/updated tests across the named-parameters and constraint-prompt
changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 13:50:08 +02:00

121 lines
4.5 KiB
JavaScript

(function () {
"use strict";
const body = document.body;
const toggle = document.querySelector(".nav-toggle");
const sidebar = document.getElementById("help-sidebar");
const search = document.getElementById("help-search");
const results = document.getElementById("search-results");
const mobile = window.matchMedia("(max-width: 760px)");
let selected = -1;
function syncToggle() {
const expanded = mobile.matches
? body.classList.contains("nav-open")
: !body.classList.contains("nav-collapsed");
toggle?.setAttribute("aria-expanded", String(expanded));
}
toggle?.addEventListener("click", function () {
body.classList.toggle(mobile.matches ? "nav-open" : "nav-collapsed");
syncToggle();
});
sidebar?.addEventListener("click", function (event) {
if (mobile.matches && event.target.closest("a")) {
body.classList.remove("nav-open");
syncToggle();
}
});
mobile.addEventListener("change", function () {
body.classList.remove("nav-open");
syncToggle();
});
function hideResults() {
results.hidden = true;
results.innerHTML = "";
selected = -1;
search?.setAttribute("aria-expanded", "false");
}
function renderResults(query) {
const terms = query.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean);
if (!terms.length) {
hideResults();
return;
}
const matches = (window.OCS_HELP_INDEX || []).map(function (entry) {
const title = entry.title.toLocaleLowerCase();
const text = entry.text.toLocaleLowerCase();
const score = terms.reduce(function (total, term) {
if (!text.includes(term) && !title.includes(term)) return -1000;
return total + (title.includes(term) ? 8 : 1);
}, 0);
return { entry: entry, score: score };
}).filter(function (item) { return item.score >= 0; })
.sort(function (a, b) { return b.score - a.score || a.entry.title.localeCompare(b.entry.title); })
.slice(0, 12);
results.innerHTML = "";
if (!matches.length) {
const empty = document.createElement("li");
empty.className = "search-empty";
empty.textContent = "No matching help topics.";
results.appendChild(empty);
} else {
matches.forEach(function (item) {
const li = document.createElement("li");
const link = document.createElement("a");
link.href = item.entry.url;
const strong = document.createElement("strong");
strong.textContent = item.entry.title;
const detail = document.createElement("span");
detail.textContent = item.entry.chapter;
link.append(strong, detail);
li.appendChild(link);
results.appendChild(li);
});
}
results.hidden = false;
search.setAttribute("aria-expanded", "true");
selected = -1;
}
search?.addEventListener("input", function () { renderResults(search.value); });
search?.addEventListener("keydown", function (event) {
const links = Array.from(results.querySelectorAll("a"));
if (event.key === "Escape") {
search.value = "";
hideResults();
return;
}
if (!links.length || !["ArrowDown", "ArrowUp", "Enter"].includes(event.key)) return;
event.preventDefault();
if (event.key === "Enter" && selected >= 0) {
links[selected].click();
return;
}
if (event.key === "ArrowDown") selected = (selected + 1) % links.length;
if (event.key === "ArrowUp") selected = selected < 0 ? links.length - 1 : (selected - 1 + links.length) % links.length;
links.forEach(function (link, index) { link.setAttribute("aria-selected", String(index === selected)); });
links[selected]?.scrollIntoView({ block: "nearest" });
});
document.addEventListener("keydown", function (event) {
const shortcut = event.key === "/" || ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k");
if (shortcut && document.activeElement !== search) {
event.preventDefault();
search?.focus();
}
});
document.addEventListener("click", function (event) {
if (!event.target.closest(".search-shell")) hideResults();
});
syncToggle();
}());