|
|
@ -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() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (eve.metaKey) { |
|
|
|
|
|
|
|
if (eve.key === 'Backspace') { |
|
|
|
|
|
|
|
setState((prevState) => { |
|
|
|
|
|
|
|
return { ...prevState, deleteKey: true } |
|
|
|
|
|
|
|
}) |
|
|
|
performDeleteion() |
|
|
|
performDeleteion() |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const deleteKeyPressUpHandler = async (eve: KeyboardEvent) => { |
|
|
|
|
|
|
|
if (eve.key === 'Delete' ) { |
|
|
|
|
|
|
|
setState((prevState) => { |
|
|
|
|
|
|
|
return { ...prevState, deleteKey: false } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
if (eve.metaKey) { |
|
|
|
if (eve.metaKey) { |
|
|
|
eve.preventDefault() |
|
|
|
|
|
|
|
if (eve.key === 'Backspace') { |
|
|
|
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 |
|
|
|