TagSpaces is an offline, open source, document manager with tagging support
fix: dnd issues cause by the new splitter component
Ilian Sapundshievb11e96f9ee31
diff --git a/src/main/mainEvents.ts b/src/main/mainEvents.tsindex ca191dcd8..2db9da147 100644--- a/src/main/mainEvents.ts+++ b/src/main/mainEvents.ts@@ -218,9 +218,13 @@ export default function loadMainEvents() {const dragIconBase64 ='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAYAAABxLuKEAAAACXBIWXMAACsPAAArDwFlCXzZAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAA3hJREFUeJztm8+LVlUYxz+PjdaULkQkQWRIGBrcDNoipIJCxYVBu9noX6DSRglTpJWCQa4qajEkGLlwL4gWRCOFOJIgpFBiObVIKVr4C3zn2+JOMF3Pw3vuzD33Pdn5wNmc+9xzvu+Xc8597nnPNUkUHmfJoAXkSjHGoRjjUIxxGOqiEzNbAzzfUX8PgBlJfy2qFUlJCrAU2AfcANRxmQW+A95csP5EpjwLfDUAQ0LlaE7GTGZgyPyys+lvsLYTPDMbBa6R18L+M/CCGvzYFOJ3JGp3MYwA401uSPGUGHHqLwB/JOivzigwFqgfAb6PbSSFMUud+lNUQzo12wkbs6xJI7kN+WwoxjgUYxyKMQ6NF18zWwtsBX6TdK59SXkQPWLMbNjMPgZuAieAtxJpyoKoEWNmy4AzwOtJ1WRE7Ih5h/+RKRBhjJk9BbzdgZasiBkxLwKrUwvJjZg15ndgIlD/Y8tasqKvMZLuAKc70JIVJcFzKMY49J1KZrYSeClwaUbStfYl5UHM4jsOhFL/j4C97crJhzKVHIoxDsUYh2KMQ8zi+wtwLFD/bctasiIm870BHOhAS1aUqeRQjHGIyXyHgBWBSw8l3WtfUh7EjJhXqf5arZf3E+oaOGUqORRjHIoxDsUYh5jM90/gfKD+estasiIm870CbOtAS1aUqeSQ4kSVdwBwDFieoL863lG32SaNpDDmtlM/6G1QT1eQmFeCl4EvApc+l/ReoP6bJgI64h5wqckNMSNmGFgfqF/lxH8NXAY2NRGSmE+avte1vvhKmgV2UT3mc2AaONz0piRPJUk/AJsZ7C7fLNUBpzcWsguQ7DMZSdfN7BWqKbUZWJOyv3k8oNqO/VLSgs8Vxwh9RHha3O9349zZ/em58p+i9Y8snhRK5utQjHEoxjjEZL6jwJHApbOSJufFPQ2cDMT9JOndWpsfAOvqgZImanG7CZ8W3SfpVj/tiyLiM761hD+n+7AW95wTdzHQ5tVQbCDus0BcD1iZ4pPF+aXvVJL0K1WKnwtTkpJn1bFrzEH87YQu6QGHuugoyhhJZ4H9DNacHrBH0lQXnUU/lSQdB7ZQvT33kil6nB7VnvNrkj7tqtMFZb5mthx4Zu4M8D91S4CNgfC79UOMZraBajvjX0iarsWtnru/87+CyyuBQ0nwHIoxDsUYh2KMw9+ZHv8EJjGI7wAAAABJRU5ErkJggg==';const icon = nativeImage.createFromDataURL(dragIconBase64);+ const paths: string[] = Array.isArray(filePath) ? filePath : [filePath];+ // Electron's Item requires `file`; `files` (when set) overrides it for the+ // multi-file case.event.sender.startDrag({- file: filePath,- icon: icon,+ file: paths[0],+ ...(paths.length > 1 && { files: paths }),+ icon,});});ipcMain.handle('postRequest', async (event, payload, endpoint, requestId) => {diff --git a/src/renderer/components/CustomDragLayer.tsx b/src/renderer/components/CustomDragLayer.tsxindex eaaaa97aa..22ec689e5 100644--- a/src/renderer/components/CustomDragLayer.tsx+++ b/src/renderer/components/CustomDragLayer.tsx@@ -1,4 +1,5 @@import React from 'react';+import { createPortal } from 'react-dom';import { XYCoord, useDragLayer } from 'react-dnd';import { FilesDragPreview } from './FilesDragPreview';import TagDragPreview from './TagDragPreview';@@ -71,12 +72,19 @@ const CustomDragLayer: React.FC<CustomDragLayerProps> = (props) => {if (!isDragging) {return null;}- return (+ // Render into document.body so position:fixed resolves against the viewport+ // rather than the nearest containing block. The Splitter panes use+ // `contain: layout paint` (and other panels apply CSS transforms), both of+ // which establish containing blocks for fixed descendants — without this+ // portal, the layer is confined to its ancestor pane and the drag preview+ // appears shifted right by the drawer width / other layout offsets.+ return createPortal(<div style={layerStyles}><div style={getItemStyles(initialOffset, currentOffset, clientOffset)}>{renderItem()}</div>- </div>+ </div>,+ document.body,);};diff --git a/src/renderer/components/FileSourceDnd.tsx b/src/renderer/components/FileSourceDnd.tsxindex b09bb51c2..b24dfe275 100644--- a/src/renderer/components/FileSourceDnd.tsx+++ b/src/renderer/components/FileSourceDnd.tsx@@ -28,9 +28,6 @@ interface Props {}const FileSourceDnd: React.FC<Props> = ({ entry, children }) => {- //const childProps = children as React.ReactElement<ChildProps>;- //const entry = childProps.props.entry;-const [collected, drag, preview] = useDrag({type: DragItemTypes.FILE,item: { entry: entry },diff --git a/src/renderer/components/drag/SelectionDragLayer.tsx b/src/renderer/components/drag/SelectionDragLayer.tsxindex 6c7b1ddd0..5d58f5e62 100644--- a/src/renderer/components/drag/SelectionDragLayer.tsx+++ b/src/renderer/components/drag/SelectionDragLayer.tsx@@ -27,6 +27,7 @@import DragItemTypes from '-/components/DragItemTypes';import { alpha, useTheme } from '@mui/material/styles';import React from 'react';+import { createPortal } from 'react-dom';import { useDragLayer } from 'react-dnd';const SelectionDragLayer: React.FC = () => {@@ -66,7 +67,12 @@ const SelectionDragLayer: React.FC = () => {zIndex: 1000,};- return (+ // Portal to document.body so position:fixed resolves against the viewport.+ // The Splitter panes use `contain: layout paint`, which establishes a+ // containing block for fixed descendants — without this portal the+ // selection rectangle is offset by the drawer width (and any other layout+ // padding between the viewport and the contained ancestor).+ return createPortal(<div style={layerStyle}><divstyle={{@@ -79,7 +85,8 @@ const SelectionDragLayer: React.FC = () => {backgroundColor: alpha(theme.palette.primary.main, 0.2),}}/>- </div>+ </div>,+ document.body,);};diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsxindex 56300f36f..a45589299 100644--- a/src/renderer/perspectives/common/CellView.tsx+++ b/src/renderer/perspectives/common/CellView.tsx@@ -266,32 +266,50 @@ function CellView(props: Props) {const key = fsEntry.path;if (fsEntry.isFile) {+ // Drag-out to Finder/Explorer goes through this small handle: a separate+ // native draggable element that calls Electron's webContents.startDrag+ // with preventDefault, so the OS drag is the only thing the user sees.+ // The card body is wrapped by FileSourceDnd → react-dnd, which handles+ // in-app DnD (Move/Copy dialog on folder drop). The two stacks can't+ // share one gesture, hence the dedicated handle.+ const showNativeDragHandle =+ nativeDragModeEnabled &&+ AppConfig.isElectron &&+ currentLocation &&+ !currentLocation.haveObjectStoreSupport() &&+ !currentLocation.haveWebDavSupport();return (<div>- {nativeDragModeEnabled &&- AppConfig.isElectron &&- currentLocation &&- !currentLocation.haveObjectStoreSupport() && (- <Box- sx={{- display: 'flex',- }}- draggable="true"- onDragStart={(e) => {- e.preventDefault();- window.electronIO.ipcRenderer.startDrag(fsEntry.path);- }}+ {showNativeDragHandle && (+ <Box+ sx={{+ display: 'flex',+ }}+ draggable="true"+ onDragStart={(e) => {+ e.preventDefault();+ const selectedNow = selectedEntriesRef.current ?? [];+ const dragSelection =+ selectedNow.length > 1 &&+ selectedNow.some((s) => s.path === fsEntry.path)+ ? selectedNow+ .filter((s) => s.isFile && s.path)+ .map((s) => s.path)+ : [fsEntry.path];+ window.electronIO.ipcRenderer.startDrag(+ dragSelection.length === 1 ? dragSelection[0] : dragSelection,+ );+ }}+ >+ <DragHandleIcon sx={{ color: theme.palette.text.primary }} />+ <Typography+ variant="caption"+ sx={{ alignSelf: 'center', opacity: 0.5, marginLeft: '5px' }}>- <DragHandleIcon sx={{ color: theme.palette.text.primary }} />- <Typography- variant="caption"- sx={{ alignSelf: 'center', opacity: 0.5, marginLeft: '5px' }}- >- {i18n.t('dragOutsideApp')}- </Typography>- </Box>- )}-+ {i18n.t('core:dragOutsideApp')}+ </Typography>+ </Box>+ )}{cellContent(fsEntry,selected,diff --git a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsxindex 765c9b056..88db35bc1 100644--- a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx+++ b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx@@ -39,7 +39,7 @@ export const SortedDirContext = createContext<SortedDirContextData>({sortedDirContent: undefined,sortBy: undefined,orderBy: undefined,- nativeDragModeEnabled: undefined,+ nativeDragModeEnabled: false,setSortBy: undefined,setOrderBy: undefined,setNativeDragModeEnabled: undefined,