@@ -22,6 +22,13 @@ const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
2222 * Actions for moving blocks with keyboard shortcuts.
2323 */
2424export class MoveActions {
25+ /**
26+ * Stored to enable us to restore monkey patch.
27+ */
28+ private oldShortcutRegistryOnKeyDown :
29+ | typeof ShortcutRegistry . registry . onKeyDown
30+ | null = null ;
31+
2532 constructor ( private mover : Mover ) { }
2633
2734 private shortcuts : ShortcutRegistry . KeyboardShortcut [ ] = [
@@ -154,6 +161,32 @@ export class MoveActions {
154161 for ( const menuItem of this . menuItems ) {
155162 ContextMenuRegistry . registry . register ( menuItem ) ;
156163 }
164+
165+ // Monkey patch shortcut registry to ignore all non-move-related
166+ // actions during a move.
167+ this . oldShortcutRegistryOnKeyDown = ShortcutRegistry . registry . onKeyDown ;
168+ ShortcutRegistry . registry . onKeyDown = ( workspace , e ) => {
169+ if ( ! this . oldShortcutRegistryOnKeyDown ) return false ;
170+ // @ts -expect-error private method
171+ const key = ShortcutRegistry . registry . serializeKeyEvent ( e ) ;
172+ const moveShortcutNames =
173+ ShortcutRegistry . registry . getShortcutNamesByKeyCode ( key ) ;
174+ if (
175+ ! this . shortcuts . some ( ( shortcut ) =>
176+ moveShortcutNames ?. includes ( shortcut . name ) ,
177+ )
178+ ) {
179+ if ( this . mover . isMoving ( workspace ) ) {
180+ return false ;
181+ }
182+ }
183+
184+ return this . oldShortcutRegistryOnKeyDown . call (
185+ ShortcutRegistry . registry ,
186+ workspace ,
187+ e ,
188+ ) ;
189+ } ;
157190 }
158191
159192 /**
@@ -166,5 +199,9 @@ export class MoveActions {
166199 for ( const menuItem of this . menuItems ) {
167200 ContextMenuRegistry . registry . unregister ( menuItem . id ) ;
168201 }
202+
203+ if ( this . oldShortcutRegistryOnKeyDown ) {
204+ ShortcutRegistry . registry . onKeyDown = this . oldShortcutRegistryOnKeyDown ;
205+ }
169206 }
170207}
0 commit comments