@@ -119,6 +119,11 @@ const commandMap = new Map();
119119/** @type {Record<string, any> } */
120120let resolvedKeyBindings = keyBindings ;
121121
122+ /** @type {Record<string, any> } */
123+ let cachedResolvedKeyBindings = { } ;
124+
125+ let resolvedKeyBindingsVersion = 0 ;
126+
122127/** @type {import("@codemirror/view").KeyBinding[] } */
123128let cachedKeymap = [ ] ;
124129
@@ -1336,6 +1341,19 @@ function resolveBindingInfo(name) {
13361341 return baseBinding ? { ...baseBinding , ...override } : override ;
13371342}
13381343
1344+ function buildResolvedKeyBindingsSnapshot ( ) {
1345+ const bindingNames = new Set ( [
1346+ ...Object . keys ( keyBindings ) ,
1347+ ...Object . keys ( resolvedKeyBindings ?? { } ) ,
1348+ ] ) ;
1349+
1350+ return Object . fromEntries (
1351+ Array . from ( bindingNames , ( name ) => [ name , resolveBindingInfo ( name ) ] ) . filter (
1352+ ( [ , binding ] ) => binding ,
1353+ ) ,
1354+ ) ;
1355+ }
1356+
13391357function toCodeMirrorKey ( combo ) {
13401358 if ( ! combo ) return null ;
13411359 const parts = combo
@@ -1377,6 +1395,7 @@ function toCodeMirrorKey(combo) {
13771395
13781396function rebuildKeymap ( ) {
13791397 const bindings = [ ] ;
1398+ cachedResolvedKeyBindings = buildResolvedKeyBindingsSnapshot ( ) ;
13801399 commandMap . forEach ( ( command , name ) => {
13811400 const bindingInfo = resolveBindingInfo ( name ) ;
13821401 command . description =
@@ -1398,6 +1417,7 @@ function rebuildKeymap() {
13981417 } ) ;
13991418 } ) ;
14001419 cachedKeymap = bindings ;
1420+ resolvedKeyBindingsVersion += 1 ;
14011421 return bindings ;
14021422}
14031423
@@ -1436,16 +1456,11 @@ export function getRegisteredCommands() {
14361456}
14371457
14381458export function getResolvedKeyBindings ( ) {
1439- const bindingNames = new Set ( [
1440- ...Object . keys ( keyBindings ) ,
1441- ...Object . keys ( resolvedKeyBindings ?? { } ) ,
1442- ] ) ;
1459+ return cachedResolvedKeyBindings ;
1460+ }
14431461
1444- return Object . fromEntries (
1445- Array . from ( bindingNames , ( name ) => [ name , resolveBindingInfo ( name ) ] ) . filter (
1446- ( [ , binding ] ) => binding ,
1447- ) ,
1448- ) ;
1462+ export function getResolvedKeyBindingsVersion ( ) {
1463+ return resolvedKeyBindingsVersion ;
14491464}
14501465
14511466export function getCommandKeymapExtension ( ) {
0 commit comments