Skip to content

Commit 6ae06df

Browse files
committed
docs: address interactive docs review feedback
1 parent f8538b6 commit 6ae06df

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

site/layouts/_partials/hooks/body-end.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<script src='{{ "js/restish-playground.js" | relURL }}?v={{ $playgroundVersion }}'></script>
55
{{ range .Params.extra_js -}}
66
{{ $scriptPath := . }}
7+
{{ if or (not (strings.HasPrefix $scriptPath "js/")) (strings.Contains $scriptPath "..") -}}
8+
{{ errorf "extra_js path %q must be relative to site/static/js/ and must not contain parent traversal" $scriptPath }}
9+
{{ end -}}
710
{{ $scriptVersion := readFile (printf "static/%s" $scriptPath) | md5 }}
811
<script src='{{ $scriptPath | relURL }}?v={{ $scriptVersion }}'></script>
912
{{ end -}}

site/scripts/test-restish-playground.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ assert.deepEqual(
109109
"output format value completion"
110110
);
111111

112+
const printCompletion = complete("restish api.rest.sh/images --rsh-print H");
113+
assert.ok(printCompletion.matches.includes("HBhbp"), "print transcript completion should include HBhbp");
114+
assert.equal(
115+
printCompletion.matches.includes("Hhbp"),
116+
false,
117+
"print transcript completion should not include the invalid Hhbp spec"
118+
);
119+
112120
assert.deepEqual(
113121
complete("restish api.rest.sh/im"),
114122
{
@@ -120,6 +128,17 @@ assert.deepEqual(
120128
"URL-ish docs path completion"
121129
);
122130

131+
assert.equal(
132+
api.shouldApplyCompletionKey({ key: "Tab", shiftKey: false }),
133+
true,
134+
"plain Tab should apply completions"
135+
);
136+
assert.equal(
137+
api.shouldApplyCompletionKey({ key: "Tab", shiftKey: true }),
138+
false,
139+
"Shift+Tab should keep the browser focus traversal behavior"
140+
);
141+
123142
const toonPlan = api.parseCommand("restish get https://api.rest.sh/items -o toon");
124143
assert.equal(toonPlan.flags.outputFormat, "toon");
125144
assert.equal(

site/static/js/restish-playground.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
const cacheCompletions = ["clear", "dir", "list"];
157157
const pluginCompletions = ["debug", "install", "list", "remove"];
158158
const contentTypeCompletions = ["json", "form"];
159-
const printCompletions = ["hbp", "hbpc", "h", "b", "Hhbp"];
159+
const printCompletions = ["hbp", "hbpc", "h", "b", "HBhbp"];
160160
const filterLangCompletions = ["restish", "jq"];
161161
const imageFormatCompletions = ["jpeg", "png", "webp", "gif", "heic"];
162162
const documentFormatCompletions = ["json", "yaml", "xml", "html", "text", "csv"];
@@ -437,6 +437,10 @@
437437
return null;
438438
}
439439

440+
function shouldApplyCompletionKey(event) {
441+
return event.key === "Tab" && !event.shiftKey;
442+
}
443+
440444
function flagCompletions(completedWords) {
441445
const flags = Array.from(valueFlags.keys())
442446
.concat(Array.from(boolFlags.keys()))
@@ -3187,7 +3191,7 @@
31873191
}
31883192

31893193
command.addEventListener("keydown", function (event) {
3190-
if (event.key === "Tab") {
3194+
if (shouldApplyCompletionKey(event)) {
31913195
event.preventDefault();
31923196
applyCompletion();
31933197
resetCommandScroll();
@@ -3233,6 +3237,7 @@
32333237
encodeTOONDocument,
32343238
parseCommand,
32353239
render,
3240+
shouldApplyCompletionKey,
32363241
toonOutput
32373242
};
32383243
}

0 commit comments

Comments
 (0)