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" ;
131
5
132
6
const surroundingPairsDelimiters : Record <
133
- ExtendedSurroundingPairName ,
7
+ SpeakableSurroundingPairName ,
134
8
[ string , string ] | null
135
9
> = {
136
10
curlyBrackets : [ "{" , "}" ] ,
@@ -150,36 +24,19 @@ const surroundingPairsDelimiters: Record<
150
24
string : null ,
151
25
collectionBoundary : null ,
152
26
} ;
27
+
153
28
const surroundingPairDelimiterToName = new CompositeKeyMap <
154
29
[ string , string ] ,
155
- SurroundingPairName
30
+ SpeakableSurroundingPairName
156
31
> ( ( pair ) => pair ) ;
157
32
158
33
for ( const [ name , pair ] of Object . entries ( surroundingPairsDelimiters ) ) {
159
34
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
+ ) ;
181
39
}
182
- return result ;
183
40
}
184
41
185
42
/**
@@ -191,12 +48,13 @@ export function surroundingPairNameToSpokenForm(
191
48
* @returns The spoken form of the surrounding pair
192
49
*/
193
50
export function surroundingPairDelimitersToSpokenForm (
51
+ spokenFormMap : SpokenFormComponentMap ,
194
52
left : string ,
195
53
right : string ,
196
- ) : string {
54
+ ) : CustomizableSpokenFormComponentForType < "pairedDelimiter" > {
197
55
const pairName = surroundingPairDelimiterToName . get ( [ left , right ] ) ;
198
56
if ( pairName == null ) {
199
57
throw Error ( `Unknown surrounding pair delimiters '${ left } ${ right } '` ) ;
200
58
}
201
- return surroundingPairNameToSpokenForm ( pairName ) ;
59
+ return spokenFormMap . pairedDelimiter [ pairName ] ;
202
60
}
0 commit comments