6
6
showError ,
7
7
} from "@cursorless/common" ;
8
8
import { isEqual } from "lodash" ;
9
+ import { dirname } from "node:path" ;
9
10
import {
11
+ DefaultSpokenFormMapEntry ,
10
12
defaultSpokenFormInfo ,
11
13
defaultSpokenFormMap ,
12
14
} from "./DefaultSpokenFormMap" ;
@@ -21,7 +23,6 @@ import {
21
23
spokenFormsPath ,
22
24
} from "./scopeProviders/getSpokenFormEntries" ;
23
25
import { ide } from "./singletons/ide.singleton" ;
24
- import { dirname } from "node:path" ;
25
26
26
27
const ENTRY_TYPES = [
27
28
"simpleScopeTypeType" ,
@@ -118,39 +119,41 @@ export class CustomSpokenForms implements SpokenFormMap {
118
119
. map ( ( { id, spokenForms } ) => [ id , spokenForms ] ) ,
119
120
) ;
120
121
122
+ const defaultEntry : Partial < Record < string , DefaultSpokenFormMapEntry > > =
123
+ defaultSpokenFormInfo [ entryType ] ;
124
+ const ids = Array . from (
125
+ new Set ( [ ...Object . keys ( defaultEntry ) , ...Object . keys ( entry ) ] ) ,
126
+ ) ;
121
127
this [ entryType ] = Object . fromEntries (
122
- Object . entries ( defaultSpokenFormInfo [ entryType ] ) . map (
123
- ( [ key , { defaultSpokenForms, isSecret } ] ) : [
124
- SpokenFormType ,
125
- SpokenFormMapEntry ,
126
- ] => {
127
- const customSpokenForms = entry [ key ] ;
128
- if ( customSpokenForms != null ) {
129
- return [
130
- key as SpokenFormType ,
131
- {
132
- defaultSpokenForms,
133
- spokenForms : customSpokenForms ,
134
- requiresTalonUpdate : false ,
135
- isCustom : isEqual ( defaultSpokenForms , customSpokenForms ) ,
136
- isSecret,
137
- } ,
138
- ] ;
139
- } else {
140
- return [
141
- key as SpokenFormType ,
142
- {
143
- defaultSpokenForms,
144
- spokenForms : [ ] ,
145
- // If it's not a secret spoken form, then it's a new scope type
146
- requiresTalonUpdate : ! isSecret ,
147
- isCustom : false ,
148
- isSecret,
149
- } ,
150
- ] ;
151
- }
152
- } ,
153
- ) ,
128
+ ids . map ( ( id ) : [ SpokenFormType , SpokenFormMapEntry ] => {
129
+ const { defaultSpokenForms = [ ] , isSecret = false } =
130
+ defaultEntry [ id ] ?? { } ;
131
+ const customSpokenForms = entry [ id ] ;
132
+ if ( customSpokenForms != null ) {
133
+ return [
134
+ id as SpokenFormType ,
135
+ {
136
+ defaultSpokenForms,
137
+ spokenForms : customSpokenForms ,
138
+ requiresTalonUpdate : false ,
139
+ isCustom : isEqual ( defaultSpokenForms , customSpokenForms ) ,
140
+ isSecret,
141
+ } ,
142
+ ] ;
143
+ } else {
144
+ return [
145
+ id as SpokenFormType ,
146
+ {
147
+ defaultSpokenForms,
148
+ spokenForms : [ ] ,
149
+ // If it's not a secret spoken form, then it's a new scope type
150
+ requiresTalonUpdate : ! isSecret ,
151
+ isCustom : false ,
152
+ isSecret,
153
+ } ,
154
+ ] ;
155
+ }
156
+ } ) ,
154
157
) as any ;
155
158
}
156
159
0 commit comments