From c4c1b764a8415717514e157211a53f130054aa11 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 7 Aug 2024 19:41:35 +0100 Subject: [PATCH] fix useEffect dependency issue. Fix platform specificity --- .../src/lib/components/file-explorer.tsx | 18 +++++++++++++----- .../workspace/src/lib/remix-ui-workspace.tsx | 2 ++ libs/remix-ui/workspace/src/lib/types/index.ts | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) 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 dc6814d275..48edc96f52 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -34,7 +34,8 @@ export const FileExplorer = (props: FileExplorerProps) => { deletePath, uploadFile, uploadFolder, - fileState + fileState, + canPaste } = props const [state, setState] = useState(workspaceState) // const [isPending, startTransition] = useTransition(); @@ -97,6 +98,8 @@ export const FileExplorer = (props: FileExplorerProps) => { } const targetDocument = treeRef.current + console.log('what does the ref contain?', { treeRef }) + targetDocument.addEventListener('keydown', keyPressHandler) targetDocument.addEventListener('keyup', keyUpHandler) return () => { @@ -171,6 +174,7 @@ export const FileExplorer = (props: FileExplorerProps) => { } props.editModeOn(feTarget[0].key, feTarget[0].type, false) } + if (treeRef.current) { const F2KeyPressHandler = async (eve: KeyboardEvent) => { if (eve.key === 'F2' ) { @@ -247,6 +251,9 @@ export const FileExplorer = (props: FileExplorerProps) => { } } + const focus = state.copyElement + console.log('copied', focus) + if (treeRef.current) { const targetDocument = treeRef.current let CopyComboHandler: (eve: KeyboardEvent) => Promise @@ -280,10 +287,11 @@ export const FileExplorer = (props: FileExplorerProps) => { return } } - } else { + } + if ((window as any).navigator.platform === 'Linux x86_64' || (window as any).navigator.platform === 'Win32') { pcCopyHandler = async (eve: KeyboardEvent) => { if (eve.ctrlKey && (eve.key === 'c' || eve.key === 'C')) { - feWindow._paq.push(['trackEvent', 'fileExplorer', 'f2ToRename', 'RenamePath']) + feWindow._paq.push(['trackEvent', 'fileExplorer', 'CtrlCToCopy', 'CopyPath']) await performCopy() return } @@ -291,7 +299,7 @@ export const FileExplorer = (props: FileExplorerProps) => { pcCutHandler = async (eve: KeyboardEvent) => { if (eve.ctrlKey && eve.code === 'KeyX') { - feWindow._paq.push(['trackEvent', 'fileExplorer', 'f2ToRename', 'RenamePath']) + feWindow._paq.push(['trackEvent', 'fileExplorer', 'CtrlXToCut', 'CutPath']) await performCut() return } @@ -322,7 +330,7 @@ export const FileExplorer = (props: FileExplorerProps) => { targetDocument?.removeEventListener('keydown', pcCopyHandler) } } - }, [treeRef.current, feTarget]) + }, [treeRef.current, feTarget, canPaste, state.copyElement.length]) 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/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 97d4614b6d..04730f24b7 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -1071,6 +1071,7 @@ export function Workspace() { renamePath={editModeOn} importFromIpfs={importFromUrl} importFromHttps={importFromUrl} + canPaste={canPaste} /> )} @@ -1088,6 +1089,7 @@ export function Workspace() { files={global.fs.localhost.files} flatTree={global.fs.localhost.flatTree} fileState={[]} + canPaste={canPaste} workspaceState={state} expandPath={global.fs.localhost.expandPath} focusEdit={global.fs.focusEdit} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index c6f9fa29e7..79c9b4afef 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -101,6 +101,7 @@ export interface FilePanelType extends ViewPlugin { export interface FileExplorerProps { name: string, menuItems?: string[], + canPaste: boolean contextMenuItems: MenuItems, removedContextMenuItems: MenuItems, files: { [x: string]: Record },