11import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index" ;
22import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter" ;
33import type { DocHandle , Prop } from "@automerge/automerge-repo" ;
4- import { type KbdKey , createShortcut } from "@solid-primitives/keyboard " ;
4+ import { makeEventListener } from "@solid-primitives/event-listener " ;
55import ListPlus from "lucide-solid/icons/list-plus" ;
66import {
77 type Component ,
@@ -17,6 +17,7 @@ import invariant from "tiny-invariant";
1717
1818import type { Cell , Notebook } from "catlog-wasm" ;
1919import { type Completion , IconButton } from "../components" ;
20+ import { type KbdKey , type ModifierKey , keyEventHasModifier } from "../util/keyboard" ;
2021import {
2122 type CellActions ,
2223 type FormalCellEditorProps ,
@@ -137,7 +138,7 @@ export function NotebookEditor<T>(props: {
137138 {
138139 name : "Text" ,
139140 description : "Start writing text" ,
140- shortcut : [ cellShortcutModifier , "T" ] ,
141+ shortcut : [ "T" ] ,
141142 construct : ( ) => newRichTextCell ( ) ,
142143 } ,
143144 ...( props . cellConstructors ?? [ ] ) ,
@@ -149,21 +150,27 @@ export function NotebookEditor<T>(props: {
149150 return {
150151 name,
151152 description,
152- shortcut,
153+ shortcut : shortcut && [ cellShortcutModifier , ... shortcut ] ,
153154 onComplete : ( ) => replaceCellWith ( i , cc . construct ( ) ) ,
154155 } ;
155156 } ) ;
156157
157- createEffect ( ( ) => {
158+ makeEventListener ( window , "keydown" , ( evt ) => {
158159 if ( props . noShortcuts ) {
159160 return ;
160161 }
161- for ( const command of insertCommands ( ) ) {
162- if ( command . shortcut ) {
163- createShortcut ( command . shortcut , ( ) => command . onComplete ?.( ) ) ;
162+ if ( keyEventHasModifier ( evt , cellShortcutModifier ) ) {
163+ for ( const command of insertCommands ( ) ) {
164+ if ( command . shortcut && evt . key . toUpperCase ( ) === command . shortcut [ 0 ] ) {
165+ command . onComplete ?.( ) ;
166+ return evt . preventDefault ( ) ;
167+ }
164168 }
165169 }
166- createShortcut ( [ "Shift" , "Enter" ] , ( ) => addAfterActiveCell ( newStemCell ( ) ) ) ;
170+ if ( evt . shiftKey && evt . key === "Enter" ) {
171+ addAfterActiveCell ( newStemCell ( ) ) ;
172+ return evt . preventDefault ( ) ;
173+ }
167174 } ) ;
168175
169176 // Set up drag and drop for notebook cells. Each cell reports to the
@@ -369,4 +376,4 @@ The choice is platform-specific: On Mac, the Alt/Option key remaps keys, so we
369376use Control, whereas on other platforms Control tends to be already bound in
370377other shortcuts, so we Alt.
371378 */
372- export const cellShortcutModifier : KbdKey = navigator . userAgent . includes ( "Mac" ) ? "Control" : "Alt" ;
379+ const cellShortcutModifier : ModifierKey = navigator . userAgent . includes ( "Mac" ) ? "Control" : "Alt" ;
0 commit comments