fix state bug

pull/4976/head
Joseph Izang 4 months ago
parent 0d8e89544c
commit 1950b9411d
  1. 44
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  2. 1
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -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

@ -202,7 +202,6 @@ export interface FileExplorerContextMenuProps {
export interface WorkSpaceState {
ctrlKey: boolean
deleteKey?: boolean
backspaceKey?: boolean
F2Key?: boolean
newFileName: string
actions: {

Loading…
Cancel
Save