1- import {
2- ModifierType ,
3- SimpleScopeTypeType ,
4- SurroundingPairName ,
5- CompositeKeyMap ,
6- } from "@cursorless/common" ;
7-
8- export const modifiers = {
9- excludeInterior : "bounds" ,
10- toRawSelection : "just" ,
11- leading : "leading" ,
12- trailing : "trailing" ,
13- keepContentFilter : "content" ,
14- keepEmptyFilter : "empty" ,
15- inferPreviousMark : "its" ,
16- startOf : "start of" ,
17- endOf : "end of" ,
18- interiorOnly : "inside" ,
19- extendThroughStartOf : "head" ,
20- extendThroughEndOf : "tail" ,
21- everyScope : "every" ,
22-
23- containingScope : null ,
24- ordinalScope : null ,
25- relativeScope : null ,
26- modifyIfUntyped : null ,
27- cascading : null ,
28- range : null ,
29- } as const satisfies Record < ModifierType , string | null > ;
30-
31- export const modifiersExtra = {
32- first : "first" ,
33- last : "last" ,
34- previous : "previous" ,
35- next : "next" ,
36- forward : "forward" ,
37- backward : "backward" ,
38- } ;
39-
40- export const scopeSpokenForms = {
41- argumentOrParameter : "arg" ,
42- attribute : "attribute" ,
43- functionCall : "call" ,
44- functionCallee : "callee" ,
45- className : "class name" ,
46- class : "class" ,
47- comment : "comment" ,
48- functionName : "funk name" ,
49- namedFunction : "funk" ,
50- ifStatement : "if state" ,
51- instance : "instance" ,
52- collectionItem : "item" ,
53- collectionKey : "key" ,
54- anonymousFunction : "lambda" ,
55- list : "list" ,
56- map : "map" ,
57- name : "name" ,
58- regularExpression : "regex" ,
59- section : "section" ,
60- sectionLevelOne : "one section" ,
61- sectionLevelTwo : "two section" ,
62- sectionLevelThree : "three section" ,
63- sectionLevelFour : "four section" ,
64- sectionLevelFive : "five section" ,
65- sectionLevelSix : "six section" ,
66- selector : "selector" ,
67- statement : "state" ,
68- string : "string" ,
69- branch : "branch" ,
70- type : "type" ,
71- value : "value" ,
72- condition : "condition" ,
73- unit : "unit" ,
74- // XML, JSX
75- xmlElement : "element" ,
76- xmlBothTags : "tags" ,
77- xmlStartTag : "start tag" ,
78- xmlEndTag : "end tag" ,
79- // LaTeX
80- part : "part" ,
81- chapter : "chapter" ,
82- subSection : "subsection" ,
83- subSubSection : "subsubsection" ,
84- namedParagraph : "paragraph" ,
85- subParagraph : "subparagraph" ,
86- environment : "environment" ,
87- // Talon
88- command : "command" ,
89- // Text-based scope types
90- character : "char" ,
91- word : "word" ,
92- token : "token" ,
93- identifier : "identifier" ,
94- line : "line" ,
95- sentence : "sentence" ,
96- paragraph : "block" ,
97- document : "file" ,
98- nonWhitespaceSequence : "paint" ,
99- boundedNonWhitespaceSequence : "short paint" ,
100- url : "link" ,
101- notebookCell : "cell" ,
102-
103- switchStatementSubject : null ,
104- [ "private.fieldAccess" ] : null ,
105- } as const satisfies Record < SimpleScopeTypeType , string | null > ;
106-
107- type ExtendedSurroundingPairName = SurroundingPairName | "whitespace" ;
108-
109- const surroundingPairsSpoken : Record <
110- ExtendedSurroundingPairName ,
111- string | null
112- > = {
113- curlyBrackets : "curly" ,
114- angleBrackets : "diamond" ,
115- escapedDoubleQuotes : "escaped quad" ,
116- escapedSingleQuotes : "escaped twin" ,
117- escapedParentheses : "escaped round" ,
118- escapedSquareBrackets : "escaped box" ,
119- doubleQuotes : "quad" ,
120- parentheses : "round" ,
121- backtickQuotes : "skis" ,
122- squareBrackets : "box" ,
123- singleQuotes : "twin" ,
124- any : "pair" ,
125- string : "string" ,
126- whitespace : "void" ,
127-
128- // Used internally by the "item" scope type
129- collectionBoundary : null ,
130- } ;
1+ import { CompositeKeyMap } from "@cursorless/common" ;
2+ import { SpeakableSurroundingPairName } from "../../spokenForms/SpokenFormType" ;
3+ import { SpokenFormComponentMap } from "../getSpokenFormComponentMap" ;
4+ import { CustomizableSpokenFormComponentForType } from "../SpokenFormComponent" ;
1315
1326const surroundingPairsDelimiters : Record <
133- ExtendedSurroundingPairName ,
7+ SpeakableSurroundingPairName ,
1348 [ string , string ] | null
1359> = {
13610 curlyBrackets : [ "{" , "}" ] ,
@@ -150,36 +24,19 @@ const surroundingPairsDelimiters: Record<
15024 string : null ,
15125 collectionBoundary : null ,
15226} ;
27+
15328const surroundingPairDelimiterToName = new CompositeKeyMap <
15429 [ string , string ] ,
155- SurroundingPairName
30+ SpeakableSurroundingPairName
15631> ( ( pair ) => pair ) ;
15732
15833for ( const [ name , pair ] of Object . entries ( surroundingPairsDelimiters ) ) {
15934 if ( pair != null ) {
160- surroundingPairDelimiterToName . set ( pair , name as SurroundingPairName ) ;
161- }
162- }
163-
164- export const surroundingPairForceDirections = {
165- left : "left" ,
166- right : "right" ,
167- } ;
168-
169- /**
170- * Given a pair name (eg `parentheses`), returns the spoken form of the
171- * surrounding pair.
172- * @param surroundingPair The name of the surrounding pair
173- * @returns The spoken form of the surrounding pair
174- */
175- export function surroundingPairNameToSpokenForm (
176- surroundingPair : SurroundingPairName ,
177- ) : string {
178- const result = surroundingPairsSpoken [ surroundingPair ] ;
179- if ( result == null ) {
180- throw Error ( `Unknown surrounding pair '${ surroundingPair } '` ) ;
35+ surroundingPairDelimiterToName . set (
36+ pair ,
37+ name as SpeakableSurroundingPairName ,
38+ ) ;
18139 }
182- return result ;
18340}
18441
18542/**
@@ -191,12 +48,13 @@ export function surroundingPairNameToSpokenForm(
19148 * @returns The spoken form of the surrounding pair
19249 */
19350export function surroundingPairDelimitersToSpokenForm (
51+ spokenFormMap : SpokenFormComponentMap ,
19452 left : string ,
19553 right : string ,
196- ) : string {
54+ ) : CustomizableSpokenFormComponentForType < "pairedDelimiter" > {
19755 const pairName = surroundingPairDelimiterToName . get ( [ left , right ] ) ;
19856 if ( pairName == null ) {
19957 throw Error ( `Unknown surrounding pair delimiters '${ left } ${ right } '` ) ;
20058 }
201- return surroundingPairNameToSpokenForm ( pairName ) ;
59+ return spokenFormMap . pairedDelimiter [ pairName ] ;
20260}
0 commit comments