fix state bug

pull/5370/head
Joseph Izang 5 months ago
parent e750831d37
commit e3eaf9dfd8
  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) { if (treeRef.current) {
const deleteKeyPressHandler = async (eve: KeyboardEvent) => { const deleteKeyPressHandler = async (eve: KeyboardEvent) => {
eve.preventDefault()
if (eve.key === 'Delete' ) { if (eve.key === 'Delete' ) {
setState((prevState) => {
return { ...prevState, deleteKey: true }
})
performDeleteion() performDeleteion()
return return
} }
if (eve.metaKey) { if (eve.metaKey) {
eve.preventDefault()
if (eve.key === 'Backspace') { 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() performDeleteion()
return return
} }
@ -127,8 +148,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
treeRef.current?.addEventListener('keydown', deleteKeyPressHandler) treeRef.current?.addEventListener('keydown', deleteKeyPressHandler)
treeRef.current?.addEventListener('keyup', deleteKeyPressUpHandler)
return () => { return () => {
treeRef.current?.removeEventListener('keydown', deleteKeyPressHandler) treeRef.current?.removeEventListener('keydown', deleteKeyPressHandler)
treeRef.current?.addEventListener('keyup', deleteKeyPressUpHandler)
} }
} }
}, [treeRef.current, feTarget]) }, [treeRef.current, feTarget])
@ -142,20 +165,31 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
if (treeRef.current) { if (treeRef.current) {
const F2KeyPressHandler = async (eve: KeyboardEvent) => { const F2KeyPressHandler = async (eve: KeyboardEvent) => {
eve.preventDefault()
if (eve.key === 'F2' ) { if (eve.key === 'F2' ) {
console.log('F2 key was pressed so renaming happening')
await performRename() 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 return
} }
} }
treeRef.current?.addEventListener('keydown', F2KeyPressHandler) treeRef.current?.addEventListener('keydown', F2KeyPressHandler)
treeRef.current?.addEventListener('keyup', F2KeyPressUpHandler)
return () => { return () => {
treeRef.current?.removeEventListener('keydown', F2KeyPressHandler) treeRef.current?.removeEventListener('keydown', F2KeyPressHandler)
treeRef.current?.addEventListener('keyup', F2KeyPressUpHandler)
} }
} }
}, [treeRef.current]) }, [treeRef.current, feTarget])
const hasReservedKeyword = (content: string): boolean => { const hasReservedKeyword = (content: string): boolean => {
if (state.reservedKeywords.findIndex((value) => content.startsWith(value)) !== -1) return true if (state.reservedKeywords.findIndex((value) => content.startsWith(value)) !== -1) return true

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

Loading…
Cancel
Save