This commit is contained in:
49lf
2024-10-07 13:38:40 -04:00
parent 85a39109f8
commit b303b678ad
2 changed files with 25 additions and 14 deletions

View File

@ -21,6 +21,7 @@ import { DeleteConfirmationDialog } from './ProjectCard/DeleteProjectDialog'
import { ContextMenu, ContextMenuItem } from './ContextMenu'
import usePlatform from 'hooks/usePlatform'
import { FileEntry } from 'lib/project'
import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher'
function getIndentationCSS(level: number) {
return `calc(1rem * ${level + 1})`
@ -125,6 +126,7 @@ const FileTreeItem = ({
level?: number
}) => {
const { send: fileSend, context: fileContext } = useFileContext()
const openDirectoriesRef = useRef<string[]>([])
const { onFileOpen, onFileClose } = useLspContext()
const navigate = useNavigate()
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false)
@ -154,6 +156,27 @@ const FileTreeItem = ({
})
}, [fileContext.itemsBeingRenamed, fileOrDir.path, fileSend])
useFileSystemWatcher(async (path) => {
console.log(path)
}, openDirectoriesRef.current)
const clickDirectory = () => {
console.log("Before", openDirectoriesRef.current)
const index = openDirectoriesRef.current.indexOf(fileOrDir.path)
if (index >= 0) {
openDirectoriesRef.current.splice(index, 1)
} else {
openDirectoriesRef.current.push(fileOrDir.path)
}
console.log("After", openDirectoriesRef.current)
fileSend({
type: 'Set selected directory',
directory: fileOrDir,
})
}
function handleKeyUp(e: React.KeyboardEvent<HTMLButtonElement>) {
if (e.metaKey && e.key === 'Backspace') {
// Open confirmation dialog
@ -241,19 +264,7 @@ const FileTreeItem = ({
: '')
}
style={{ paddingInlineStart: getIndentationCSS(level) }}
onClick={(e) => e.currentTarget.focus()}
onClickCapture={(e) =>
fileSend({
type: 'Set selected directory',
directory: fileOrDir,
})
}
onFocusCapture={(e) =>
fileSend({
type: 'Set selected directory',
directory: fileOrDir,
})
}
onClick={clickDirectory}
onKeyDown={(e) => e.key === 'Enter' && e.preventDefault()}
onKeyUp={handleKeyUp}
>

View File

@ -31,7 +31,7 @@ const isLinux = os.platform() === 'linux'
let fsWatchListeners = new Map<string, ReturnType<typeof chokidar.watch>>()
const watchFileOn = (path: string, callback: (path: string) => void) => {
const watchFileOn = (path: string, callback: (event: string, path: string) => void) => {
const watcherMaybe = fsWatchListeners.get(path)
if (watcherMaybe) return
const watcher = chokidar.watch(path)