Skip to content

Commit 446aada

Browse files
Added references for actions, modifiers, and scopes in docs (#3304)
1 parent 518b132 commit 446aada

242 files changed

Lines changed: 3420 additions & 623 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cursorless-talon/src/cheatsheet/sections/scopes.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def get_scopes() -> list[ListItemDescriptor]:
99
"scopeType",
1010
{
1111
"argumentOrParameter": "Argument",
12-
"boundedNonWhitespaceSequence": "Non-whitespace sequence bounded by surrounding pair delimeters",
13-
"boundedParagraph": "Paragraph bounded by surrounding pair delimeters",
12+
"boundedNonWhitespaceSequence": "Non-whitespace sequence bounded by surrounding pair delimiters",
13+
"boundedParagraph": "Paragraph bounded by surrounding pair delimiters",
1414
},
1515
)
1616

‎oxlint.config.mts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const disabledRules = [
5858
"react/forbid-component-props",
5959
"react/jsx-max-depth",
6060
"react/jsx-no-literals",
61+
"react/no-array-index-key",
6162
"react/no-multi-comp",
6263
"react/only-export-components",
6364
"react/react-in-jsx-scope",

‎packages/app-web-docs/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"unist-util-visit": "^5.1.0"
4343
},
4444
"devDependencies": {
45+
"@cursorless/lib-common": "workspace:*",
4546
"@cursorless/lib-node-common": "workspace:*",
4647
"@docusaurus/module-type-aliases": "^3.10.2",
4748
"@docusaurus/types": "^3.10.2",

‎packages/app-web-docs/src/css/custom.scss‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@
2525
.pointer {
2626
cursor: pointer;
2727
}
28+
29+
.list-unstyled {
30+
padding-left: 1rem;
31+
list-style: none;
32+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React, { Fragment } from "react";
2+
import {
3+
actionReferences,
4+
modifierReferences,
5+
scopeReferences,
6+
} from "@cursorless/lib-common";
7+
import type { ReferenceEntry } from "@cursorless/lib-common";
8+
9+
export function ActionReference({ id }: { id: keyof typeof actionReferences }) {
10+
return <ReferenceEntryComponent id={id} entry={actionReferences[id]} />;
11+
}
12+
13+
export function ModifierReference({
14+
id,
15+
}: {
16+
id: keyof typeof modifierReferences;
17+
}) {
18+
return <ReferenceEntryComponent id={id} entry={modifierReferences[id]} />;
19+
}
20+
21+
export function ScopeReference({ id }: { id: keyof typeof scopeReferences }) {
22+
return <ReferenceEntryComponent id={id} entry={scopeReferences[id]} />;
23+
}
24+
25+
function ReferenceEntryComponent({
26+
id,
27+
entry,
28+
}: {
29+
id: string;
30+
entry: ReferenceEntry;
31+
}) {
32+
return (
33+
<>
34+
{entry.description != null && <p>{entry.description}</p>}
35+
36+
<p>
37+
Cursorless ID: <code>{id}</code>
38+
</p>
39+
40+
{entry.defaultSpokenForm != null && (
41+
<div className="mb-3">
42+
<div>
43+
Default spoken form: <code>{entry.defaultSpokenForm}</code>
44+
</div>
45+
46+
{entry.legacySpokenForms != null && (
47+
<div>
48+
Legacy spoken forms:{" "}
49+
{entry.legacySpokenForms.map((s, i) => (
50+
<Fragment key={s}>
51+
{i > 0 && ", "}
52+
<code>{s}</code>
53+
</Fragment>
54+
))}
55+
</div>
56+
)}
57+
58+
{entry.disabledByDefault && (
59+
<div>
60+
<strong>Disabled by default</strong>
61+
</div>
62+
)}
63+
</div>
64+
)}
65+
66+
{entry.syntaxes.length > 0 && (
67+
<div>
68+
Syntax:
69+
<ul className="list-unstyled">
70+
{entry.syntaxes.map((syntax, index) => (
71+
<li key={index}>
72+
{formatPattern(syntax.pattern, entry.defaultSpokenForm)}:{" "}
73+
{formatPattern(syntax.description)}
74+
</li>
75+
))}
76+
</ul>
77+
</div>
78+
)}
79+
80+
{entry.examples.length > 0 && (
81+
<div>
82+
Examples:
83+
<ul className="list-unstyled">
84+
{entry.examples.map((example, index) => (
85+
<li key={index}>
86+
<code>
87+
&quot;
88+
{formatPattern(example.spokenForm, entry.defaultSpokenForm)}
89+
&quot;
90+
</code>
91+
: {example.description}
92+
</li>
93+
))}
94+
</ul>
95+
</div>
96+
)}
97+
</>
98+
);
99+
}
100+
101+
function formatPattern(
102+
pattern: string,
103+
defaultSpokenForm?: string,
104+
): React.ReactNode[] {
105+
return pattern.split(/(<[\w ]+>)/gu).map((part, index) => {
106+
if (part.startsWith("<") && part.endsWith(">")) {
107+
if (part === "<spokenForm>") {
108+
return defaultSpokenForm ?? "???";
109+
}
110+
return <code key={index}>{part}</code>;
111+
}
112+
return part;
113+
});
114+
}

‎packages/app-web-docs/src/docs/components/ScopeVisualizer.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ import type {
77
import {
88
prettifyLanguageName,
99
prettifyScopeType,
10+
scopeReferences,
1011
serializeScopeType,
1112
} from "@cursorless/lib-common";
1213
import { generateDecorations } from "./calculateHighlights";
1314
import { Code } from "./Code";
1415
import { H2, H3, H4, H5 } from "./Header";
1516
import "./ScopeSupport.css";
1617
import type { FacetValue, Fixture, RangeType, ScopeTests } from "./types";
17-
import {
18-
getFacetInfo,
19-
isScopeInternal,
20-
nameComparator,
21-
prettifyFacet,
22-
} from "./util";
18+
import { getFacetInfo, nameComparator, prettifyFacet } from "./util";
2319

2420
interface Scopes {
2521
public: Scope[];
@@ -57,6 +53,10 @@ export function ScopeVisualizer({ languageId, scopeTypeType }: Props) {
5753
scopeTypeType != null,
5854
);
5955

56+
if (scopes.internal.length === 0 && scopes.public.length === 0) {
57+
return null;
58+
}
59+
6060
const renderOptions = () => {
6161
return (
6262
<div className="mb-4">
@@ -322,7 +322,7 @@ function getScopeFixtures(
322322
for (const f of scope.facets) {
323323
f.fixtures.sort(nameComparator);
324324
}
325-
if (isScopeInternal(scope.scopeTypeType)) {
325+
if (scopeReferences[scope.scopeTypeType].private) {
326326
result.internal.push(scope);
327327
} else {
328328
result.public.push(scope);

packages/app-web-docs/src/docs/contributing/scopes/components/Scopes.tsx renamed to packages/app-web-docs/src/docs/components/Scopes.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
22
import type { ScopeTypeType } from "@cursorless/lib-common";
3-
import { DynamicTOC } from "../../../components/DynamicTOC";
4-
import { ScopeVisualizer } from "../../../components/ScopeVisualizer";
5-
import { ScrollToHashId } from "../../../components/ScrollToHashId";
3+
import { DynamicTOC } from "./DynamicTOC";
4+
import { ScopeVisualizer } from "./ScopeVisualizer";
5+
import { ScrollToHashId } from "./ScrollToHashId";
66

77
interface Props {
88
scopeTypeType: ScopeTypeType;

‎packages/app-web-docs/src/docs/components/util.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
PlaintextScopeSupportFacet,
33
ScopeSupportFacet,
44
ScopeSupportFacetInfo,
5-
ScopeTypeType,
65
} from "@cursorless/lib-common";
76
import {
87
camelCaseToAllDown,
@@ -64,16 +63,3 @@ export function nameComparator(
6463
): number {
6564
return a.name.localeCompare(b.name, undefined, { numeric: true });
6665
}
67-
68-
export function isScopeInternal(scope: ScopeTypeType): boolean {
69-
switch (scope) {
70-
case "disqualifyDelimiter":
71-
case "pairDelimiter":
72-
case "textFragment":
73-
case "interior":
74-
case "surroundingPairInterior":
75-
return true;
76-
default:
77-
return false;
78-
}
79-
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"label": "Private scopes"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Scopes } from "@site/src/docs/components/Scopes";
2+
3+
# Custom regex
4+
5+
<Scopes scopeTypeType="customRegex" />

0 commit comments

Comments
 (0)