obsidian-db-folder icon indicating copy to clipboard operation
obsidian-db-folder copied to clipboard

Cannot drag/drop files after viewing the database

Open Mazarkus opened this issue 2 years ago • 6 comments

Describe the bug After creating a new database file to mess around, I discovered I could no longer drag-drop files within my vault file structure. I was able to recover the capability by restarting the program, but as soon as I viewed a database (even when only in markdown), I was then unable to move files around.

To Reproduce

  1. Make sure Dataview and DB Folder are installed and enabled
  2. open a database note
  3. attempt to move a file to another folder (doesn't matter which file)
  4. open the file (so the database note isn't active)
  5. restart obsidian
  6. attempt to move the file (should be successful now)

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Version: 2.0.1

Additional context I have attempted to disable all of my other plugins, and with only "Dataview" and "DB Folder" enabled, I still have the problem If all plugins are disabled, I can successfully move files even after viewing the database note (now exclusively in markdown)

Mazarkus avatar Aug 04 '22 02:08 Mazarkus

I will investigate the cause. Thanks for the report!

RafaelGB avatar Aug 04 '22 06:08 RafaelGB

Something inside this react-dnd is affecting the DnD of Obsidian. Not not if Obsidian use the same library and exist an incompatibility because we are doing nothing special here, its the official example of react-dnd documentation

const [{ isDragging, handlerId }, drag] = useDrag(
    () => ({
      type: DnDConfiguration.DRAG_TYPE,
      item: { id, originalIndex },
      collect: (monitor) => ({
        handlerId: monitor.getHandlerId(),
        isDragging: monitor.isDragging(),
      }),
      end: (item, monitor) => {
        const { id: droppedId, originalIndex } = item;
        const didDrop = monitor.didDrop();
        if (!didDrop) {
          moveColumn(originalIndex, droppedId);
        }
      },
    }),
    [id, originalIndex, findColumn]
  );

  const [, drop] = useDrop(
    () => ({
      accept: DnDConfiguration.DRAG_TYPE,
      hover({ id: draggedId }: DragItem) {
        if (draggedId !== id) {
          const { index: overIndex } = findColumn(id);
          moveColumn(overIndex, draggedId);
        }
      },
    }),
    [findColumn]
  );

Still Working on it

RafaelGB avatar Aug 04 '22 06:08 RafaelGB

Maybe relation with https://github.com/react-dnd/react-dnd/issues/3304

RafaelGB avatar Aug 04 '22 07:08 RafaelGB

Thanks for looking into this! I'm just glad to know I wasn't imagining things.

Mazarkus avatar Aug 06 '22 14:08 Mazarkus

I found a way to fix this issue (an the official library opened issue too!) I left the comment that I shared with the community https://github.com/react-dnd/react-dnd/issues/3304#issuecomment-1208215687

Will be available with the next version, which will be an official one

RafaelGB avatar Aug 08 '22 14:08 RafaelGB

I will reopen this because still being a problem. Not for DnD of Obsidian but with the plugin itself.

The solution should be with the context property but not the way I expose

RafaelGB avatar Aug 09 '22 14:08 RafaelGB

working on this but without result yet. Use a documentFragment with React is nearly impossible or I don't know the way to do it.

I can't find a method of obsidian to reload its dnd when the database is closed.

Column dnd will remain disabled for now

RafaelGB avatar Aug 15 '22 13:08 RafaelGB

Until find a way to fix this, I will enable a configuration to can use the actual DnD. You can disable it if you want Screenshot 2022-08-18 at 16 37 24

RafaelGB avatar Aug 18 '22 14:08 RafaelGB

The most promising way is this example using frames (different context of Obsidian by force)

https://react-dnd.github.io/react-dnd/examples/dustbin/iframe

Dnd does not break the app but works with an iframe requires several refactors and I am not sure if is a good idea

RafaelGB avatar Aug 18 '22 14:08 RafaelGB

https://github.com/atlassian/react-beautiful-dnd just update and it is now compatible with react 18! A solid fix for this issue maybe?

RafaelGB avatar Aug 31 '22 11:08 RafaelGB

react-beautiful-dnd breaks the resize, so is not worth it

RafaelGB avatar Sep 01 '22 19:09 RafaelGB

fixed thanks to this tutorial =)

https://web.dev/drag-and-drop/

ready for the next version

RafaelGB avatar Sep 08 '22 22:09 RafaelGB

Seems to be working for me too, thanks for investigating!

Mazarkus avatar Sep 10 '22 17:09 Mazarkus