|
| 1 | +import { mapValues } from "lodash"; |
| 2 | +import { |
| 3 | + SpokenFormMap, |
| 4 | + SpokenFormMapEntry, |
| 5 | + SpokenFormMapKeyTypes, |
| 6 | +} from "./SpokenFormMap"; |
| 7 | + |
| 8 | +type DefaultSpokenFormMapDefinition = { |
| 9 | + readonly [K in keyof SpokenFormMapKeyTypes]: Readonly< |
| 10 | + Record<SpokenFormMapKeyTypes[K], string | DefaultSpokenFormMapEntry> |
| 11 | + >; |
| 12 | +}; |
| 13 | + |
| 14 | +const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = { |
| 15 | + pairedDelimiter: { |
| 16 | + curlyBrackets: "curly", |
| 17 | + angleBrackets: "diamond", |
| 18 | + escapedDoubleQuotes: "escaped quad", |
| 19 | + escapedSingleQuotes: "escaped twin", |
| 20 | + escapedParentheses: "escaped round", |
| 21 | + escapedSquareBrackets: "escaped box", |
| 22 | + doubleQuotes: "quad", |
| 23 | + parentheses: "round", |
| 24 | + backtickQuotes: "skis", |
| 25 | + squareBrackets: "box", |
| 26 | + singleQuotes: "twin", |
| 27 | + any: "pair", |
| 28 | + string: "string", |
| 29 | + whitespace: "void", |
| 30 | + }, |
| 31 | + |
| 32 | + simpleScopeTypeType: { |
| 33 | + argumentOrParameter: "arg", |
| 34 | + attribute: "attribute", |
| 35 | + functionCall: "call", |
| 36 | + functionCallee: "callee", |
| 37 | + className: "class name", |
| 38 | + class: "class", |
| 39 | + comment: "comment", |
| 40 | + functionName: "funk name", |
| 41 | + namedFunction: "funk", |
| 42 | + ifStatement: "if state", |
| 43 | + instance: "instance", |
| 44 | + collectionItem: "item", |
| 45 | + collectionKey: "key", |
| 46 | + anonymousFunction: "lambda", |
| 47 | + list: "list", |
| 48 | + map: "map", |
| 49 | + name: "name", |
| 50 | + regularExpression: "regex", |
| 51 | + section: "section", |
| 52 | + sectionLevelOne: disabledByDefault("one section"), |
| 53 | + sectionLevelTwo: disabledByDefault("two section"), |
| 54 | + sectionLevelThree: disabledByDefault("three section"), |
| 55 | + sectionLevelFour: disabledByDefault("four section"), |
| 56 | + sectionLevelFive: disabledByDefault("five section"), |
| 57 | + sectionLevelSix: disabledByDefault("six section"), |
| 58 | + selector: "selector", |
| 59 | + statement: "state", |
| 60 | + branch: "branch", |
| 61 | + type: "type", |
| 62 | + value: "value", |
| 63 | + condition: "condition", |
| 64 | + unit: "unit", |
| 65 | + // XML, JSX |
| 66 | + xmlElement: "element", |
| 67 | + xmlBothTags: "tags", |
| 68 | + xmlStartTag: "start tag", |
| 69 | + xmlEndTag: "end tag", |
| 70 | + // LaTeX |
| 71 | + part: "part", |
| 72 | + chapter: "chapter", |
| 73 | + subSection: "subsection", |
| 74 | + subSubSection: "subsubsection", |
| 75 | + namedParagraph: "paragraph", |
| 76 | + subParagraph: "subparagraph", |
| 77 | + environment: "environment", |
| 78 | + // Talon |
| 79 | + command: "command", |
| 80 | + // Text-based scope types |
| 81 | + character: "char", |
| 82 | + word: "word", |
| 83 | + token: "token", |
| 84 | + identifier: "identifier", |
| 85 | + line: "line", |
| 86 | + sentence: "sentence", |
| 87 | + paragraph: "block", |
| 88 | + document: "file", |
| 89 | + nonWhitespaceSequence: "paint", |
| 90 | + boundedNonWhitespaceSequence: "short paint", |
| 91 | + url: "link", |
| 92 | + notebookCell: "cell", |
| 93 | + |
| 94 | + string: secret("parse tree string"), |
| 95 | + switchStatementSubject: secret("subject"), |
| 96 | + }, |
| 97 | + |
| 98 | + surroundingPairForceDirection: { |
| 99 | + left: "left", |
| 100 | + right: "right", |
| 101 | + }, |
| 102 | + |
| 103 | + simpleModifier: { |
| 104 | + excludeInterior: "bounds", |
| 105 | + toRawSelection: "just", |
| 106 | + leading: "leading", |
| 107 | + trailing: "trailing", |
| 108 | + keepContentFilter: "content", |
| 109 | + keepEmptyFilter: "empty", |
| 110 | + inferPreviousMark: "its", |
| 111 | + startOf: "start of", |
| 112 | + endOf: "end of", |
| 113 | + interiorOnly: "inside", |
| 114 | + extendThroughStartOf: "head", |
| 115 | + extendThroughEndOf: "tail", |
| 116 | + everyScope: "every", |
| 117 | + }, |
| 118 | + |
| 119 | + modifierExtra: { |
| 120 | + first: "first", |
| 121 | + last: "last", |
| 122 | + previous: "previous", |
| 123 | + next: "next", |
| 124 | + forward: "forward", |
| 125 | + backward: "backward", |
| 126 | + }, |
| 127 | + |
| 128 | + customRegex: {}, |
| 129 | +}; |
| 130 | + |
| 131 | +function disabledByDefault( |
| 132 | + ...spokenForms: string[] |
| 133 | +): DefaultSpokenFormMapEntry { |
| 134 | + return { |
| 135 | + defaultSpokenForms: spokenForms, |
| 136 | + isDisabledByDefault: true, |
| 137 | + isSecret: false, |
| 138 | + }; |
| 139 | +} |
| 140 | + |
| 141 | +function secret(...spokenForms: string[]): DefaultSpokenFormMapEntry { |
| 142 | + return { |
| 143 | + defaultSpokenForms: spokenForms, |
| 144 | + isDisabledByDefault: true, |
| 145 | + isSecret: true, |
| 146 | + }; |
| 147 | +} |
| 148 | + |
| 149 | +export interface DefaultSpokenFormMapEntry { |
| 150 | + defaultSpokenForms: string[]; |
| 151 | + isDisabledByDefault: boolean; |
| 152 | + isSecret: boolean; |
| 153 | +} |
| 154 | + |
| 155 | +export type DefaultSpokenFormMap = { |
| 156 | + readonly [K in keyof SpokenFormMapKeyTypes]: Readonly< |
| 157 | + Record<SpokenFormMapKeyTypes[K], DefaultSpokenFormMapEntry> |
| 158 | + >; |
| 159 | +}; |
| 160 | + |
| 161 | +// FIXME: Don't cast here; need to make our own mapValues with stronger typing |
| 162 | +// using tricks from our object.d.ts |
| 163 | +export const defaultSpokenFormInfo = mapValues( |
| 164 | + defaultSpokenFormMapCore, |
| 165 | + (entry) => |
| 166 | + mapValues(entry, (subEntry) => |
| 167 | + typeof subEntry === "string" |
| 168 | + ? { |
| 169 | + defaultSpokenForms: [subEntry], |
| 170 | + isDisabledByDefault: false, |
| 171 | + isSecret: false, |
| 172 | + } |
| 173 | + : subEntry, |
| 174 | + ), |
| 175 | +) as DefaultSpokenFormMap; |
| 176 | + |
| 177 | +// FIXME: Don't cast here; need to make our own mapValues with stronger typing |
| 178 | +// using tricks from our object.d.ts |
| 179 | +export const defaultSpokenFormMap = mapValues(defaultSpokenFormInfo, (entry) => |
| 180 | + mapValues( |
| 181 | + entry, |
| 182 | + ({ |
| 183 | + defaultSpokenForms, |
| 184 | + isDisabledByDefault, |
| 185 | + isSecret, |
| 186 | + }): SpokenFormMapEntry => ({ |
| 187 | + spokenForms: isDisabledByDefault ? [] : defaultSpokenForms, |
| 188 | + isCustom: false, |
| 189 | + defaultSpokenForms, |
| 190 | + requiresTalonUpdate: false, |
| 191 | + isSecret, |
| 192 | + }), |
| 193 | + ), |
| 194 | +) as SpokenFormMap; |
0 commit comments