Skip to content

Dragging an item from Eagle into a note re-imports it into Eagle and leaves a broken link #6

Open

Description

@andriykoval

Plugin version: 1.8.4
Eagle: 4.0.0 (macOS)
Settings: imagePasteBehavior: "eagle", linkMode: "cmds-eagle"

What happens

  1. Drag an existing item from the Eagle app into a Markdown note.
  2. The plugin imports the file into Eagle again (addFromPath), and the note gets a link to the new item ID.
  3. Eagle shows its duplicate dialog. If you choose Keep existing, Eagle discards the new item.
  4. The note now points to a <NEW_ID>.info/ folder that no longer exists, so the image is broken and eagle://item/<NEW_ID> opens nothing.

Pasting a path to an Eagle library file works correctly: willHandlePaste → isEagleLibraryPath → handleEagleLibraryPathPaste links the existing item. Drop has no such check.

Cause

willHandleDrop / handleDrop only check allFilesAreImages(files) and always send the files to captureImageFiles. They never look at where the dropped file lives. A drag from Eagle provides files that are already inside <Library>.library/images/<ID>.info/.

Second, smaller issue

When an Eagle library path is recognized (the paste path today, and drop after the fix below), handleEagleLibraryPathPaste inserts a bare ![name](file:///…) link. It ignores linkMode, so there is no metadata line and no Open in Eagle link, unlike import. It could reuse buildEmbedForItem.

Suggested fix

I tested this as a patch to the built main.js (1.8.4), and both issues are fixed. Translated back to the source, roughly:

// Electron ≥ 32 removed File.path; use webUtils with a fallback
getDroppedFilePath(file) {
  try {
    const { webUtils } = require("electron");
    const p = webUtils?.getPathForFile?.(file);
    if (p) return p;
  } catch {}
  return file.path || "";
}

willHandleDrop(evt) {
  const files = evt.dataTransfer?.files;
  if (files && Array.from(files).some(f => this.isEagleLibraryPath(this.getDroppedFilePath(f))))
    return true;                                   // must be decided synchronously
  if (!files || !this.allFilesAreImages(files)) return false;
  return this.settings.imagePasteBehavior !== "local";
}

async handleDrop(evt, editor) {
  const files = evt.dataTransfer?.files;
  if (!files) return;
  const fromEagle = [], others = [];
  for (const f of Array.from(files)) {
    const p = this.getDroppedFilePath(f);
    if (this.isEagleLibraryPath(p)) fromEagle.push(p);
    else others.push(f);
  }
  for (let i = 0; i < fromEagle.length; i++) {
    await this.handleEagleLibraryPathPaste(fromEagle[i], editor);   // link, don't re-import
    if (i < fromEagle.length - 1 || others.length) editor.replaceSelection("\n");
  }
  if (others.length && this.allFilesAreImages(others) && this.settings.imagePasteBehavior !== "local")
    await this.captureImageFiles(others, editor);
}

And in handleEagleLibraryPathPaste, when the item is found:

const notePath = this.app.workspace.getActiveFile()?.path ?? "";
editor.replaceSelection(
  await this.buildEmbedForItem(item, notePath, { originalFilePath: originalPath })
);

Result: dragging from Eagle inserts the same canonical embed as import (respecting linkMode), with no duplicate dialog and no orphaned IDs. Drops from Finder or a browser still go through import as before.

Unrelated nit: the console still logs Loading plugin v1.6.0 while the manifest says 1.8.4.

Thanks for the plugin!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions