diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 31011a98cd..23783919b9 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -112,14 +112,35 @@ export const FileExplorer = (props: FileExplorerProps) => { if (treeRef.current) { const deleteKeyPressHandler = async (eve: KeyboardEvent) => { - eve.preventDefault() if (eve.key === 'Delete' ) { + setState((prevState) => { + return { ...prevState, deleteKey: true } + }) performDeleteion() return } if (eve.metaKey) { - eve.preventDefault() if (eve.key === 'Backspace') { + setState((prevState) => { + return { ...prevState, deleteKey: true } + }) + performDeleteion() + return + } + } + } + const deleteKeyPressUpHandler = async (eve: KeyboardEvent) => { + if (eve.key === 'Delete' ) { + setState((prevState) => { + return { ...prevState, deleteKey: false } + }) + return + } + if (eve.metaKey) { + if (eve.key === 'Backspace') { + setState((prevState) => { + return { ...prevState, deleteKey: false } + }) performDeleteion() return } @@ -127,8 +148,10 @@ export const FileExplorer = (props: FileExplorerProps) => { } treeRef.current?.addEventListener('keydown', deleteKeyPressHandler) + treeRef.current?.addEventListener('keyup', deleteKeyPressUpHandler) return () => { treeRef.current?.removeEventListener('keydown', deleteKeyPressHandler) + treeRef.current?.addEventListener('keyup', deleteKeyPressUpHandler) } } }, [treeRef.current, feTarget]) @@ -142,20 +165,31 @@ export const FileExplorer = (props: FileExplorerProps) => { } if (treeRef.current) { const F2KeyPressHandler = async (eve: KeyboardEvent) => { - eve.preventDefault() if (eve.key === 'F2' ) { - console.log('F2 key was pressed so renaming happening') await performRename() + setState((prevState) => { + return { ...prevState, F2Key: true } + }) + return + } + } + const F2KeyPressUpHandler = async (eve: KeyboardEvent) => { + if (eve.key === 'F2' ) { + setState((prevState) => { + return { ...prevState, F2Key: false } + }) return } } treeRef.current?.addEventListener('keydown', F2KeyPressHandler) + treeRef.current?.addEventListener('keyup', F2KeyPressUpHandler) return () => { treeRef.current?.removeEventListener('keydown', F2KeyPressHandler) + treeRef.current?.addEventListener('keyup', F2KeyPressUpHandler) } } - }, [treeRef.current]) + }, [treeRef.current, feTarget]) const hasReservedKeyword = (content: string): boolean => { if (state.reservedKeywords.findIndex((value) => content.startsWith(value)) !== -1) return true diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 89c50f79fa..a1c71efa2f 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -202,7 +202,6 @@ export interface FileExplorerContextMenuProps { export interface WorkSpaceState { ctrlKey: boolean deleteKey?: boolean - backspaceKey?: boolean F2Key?: boolean newFileName: string actions: {