66 showError ,
77} from "@cursorless/common" ;
88import { isEqual } from "lodash" ;
9+ import { dirname } from "node:path" ;
910import {
11+ DefaultSpokenFormMapEntry ,
1012 defaultSpokenFormInfo ,
1113 defaultSpokenFormMap ,
1214} from "./DefaultSpokenFormMap" ;
@@ -21,7 +23,6 @@ import {
2123 spokenFormsPath ,
2224} from "./scopeProviders/getSpokenFormEntries" ;
2325import { ide } from "./singletons/ide.singleton" ;
24- import { dirname } from "node:path" ;
2526
2627const ENTRY_TYPES = [
2728 "simpleScopeTypeType" ,
@@ -118,39 +119,41 @@ export class CustomSpokenForms implements SpokenFormMap {
118119 . map ( ( { id, spokenForms } ) => [ id , spokenForms ] ) ,
119120 ) ;
120121
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+ ) ;
121127 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+ } ) ,
154157 ) as any ;
155158 }
156159
0 commit comments