Skip to content

Commit e244491

Browse files
committed
Commands: allow linking to commands using the HTML fragment
1 parent 5d76993 commit e244491

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

pages/command_listing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h2 id="misc" data-group="misc">Miscellaneous</h2>
3838
</main>
3939

4040
<template id="command">
41-
<div class="command">
41+
<div class="command" id="example-command-name">
4242
<h3>
4343
<code>an-example-command</code>
4444
<span class="key-bindings"></span>

pages/command_listing.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ async function populatePage() {
4242
const keys = Object.values(commandToOptionsToKeys[command.name] || {})
4343
.flat(1);
4444
const el = commandTemplate.cloneNode(true);
45-
el.querySelector(".command").dataset.command = command.name; // used by tests
45+
// Used for linking to commands using the URL fragment, and by the tests.
46+
el.querySelector(".command").id = command.name;
4647
el.querySelector("h3 code").textContent = command.name;
4748

4849
const keysEl = el.querySelector(".key-bindings");

tests/unit_tests/command_listing_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ context("command listing", () => {
4141

4242
should("show key mappings for mapped commands", async () => {
4343
const getKeys = (commandName) => {
44-
const el = globalThis.document.querySelector(`.command[data-command=${commandName}]`);
44+
const el = globalThis.document.querySelector(`.command#${commandName}`);
4545
if (!el) throw new Error(`${commandName} el not found.`);
4646
const keys = Array.from(el.querySelectorAll(".key")).map((el) => el.textContent);
4747
return keys;

0 commit comments

Comments
 (0)