Skip to content

Feature: Add ability to drag and drop images to MarkdownEditor#14587

Merged
koppor merged 15 commits intoJabRef:mainfrom
ganesh-vk:markdown-dragdrop
Dec 24, 2025
Merged

Feature: Add ability to drag and drop images to MarkdownEditor#14587
koppor merged 15 commits intoJabRef:mainfrom
ganesh-vk:markdown-dragdrop

Conversation

@ganesh-vk
Copy link
Copy Markdown
Contributor

@ganesh-vk ganesh-vk commented Dec 12, 2025

Closes #10559

I've looked at the JavaFX documentation for dragging and dropping events and think I'm doing everything correctly. However I cannot seem to trigger the DRAG_DROPPED event at all. I've tried to debug and the DRAG_OVER event is being triggered everytime but the dropping isn't working. Please let me know what I should try to fix this.

Steps to test

  • Open a library and ensure Library file directory is set
  • Drag and drop an image into the comments section of any entry
  • The image is appended to the comments field and rendered, it is also saved in the specified directory

Screenshots:

image

Mandatory checks

@ganesh-vk ganesh-vk changed the title Markdown dragdrop Feature: Add ability to drag and drop images to MarkdownEditor Dec 12, 2025
@Siedlerchr
Copy link
Copy Markdown
Member

Which OS are you using? Windows? Mac? Linux?

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

I'm using Linux (Fedora)

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 12, 2025

I've looked at the JavaFX documentation for dragging and dropping events and think I'm doing everything correctly. However I cannot seem to trigger the DRAG_DROPPED event at all.

Do a breakpoint at org.jabref.gui.fieldeditors.LinkedFilesEditor#handleOnDragDropped - and drop a file into the linked files editor (which is part of the Entry Editor)

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

Jabref-LinkedFilesEditor.mp4

I looked at the class and assume me dragging one file below the other or vice versa should reorder them, but as you can see from the video only the handleOnDragDetected event is being triggered here. Am I doing something wrong or understanding this incorrectly?

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

@Siedlerchr @koppor Please take a look when you find the time

@Siedlerchr
Copy link
Copy Markdown
Member

@ganesh-vk Thanks for the video. I could reproduce it. It's a bug.
The PR #12871 broke the reordering. I am having a fix, will make a PR for it

@Siedlerchr
Copy link
Copy Markdown
Member

If you merge in the latest main it will probably also work for your case

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

If you merge in the latest main it will probably also work for your case

Yes, it works now, thanks for the fix! However I'm unable to figure out how MarkdownEditor uses ViewModelListCellFactory, if you can explain how that would be great.

Related to the original issue, JavaFX WebView does not support all image types ref. Do I change IMAGE in StandardFileType to include only those supported, or create a helper method within MarkdownEditor to check only those formats supported? PreviewViewer's setPreviewText will need a <base> tag to specify the relative file path as well looks like.

Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Steps to test missing - why?
  2. Screenshot missing - you can update the PR description to guide maintainers

Related to the original issue, JavaFX WebView does not support all image types ref.

What are "all images types"?

I think, it does not matter here. I just want to drag'n'drop an image from Windows explorer to the text field.

"png" from the issue description is listed there. So, what is the issue?

You can allow attachment of any file - the bibtex could be rendered by another tool, too. It is "just" an exchange format.

PreviewViewer's setPreviewText will need a <base> tag to specify the relative file path as well looks like.

Follow https://devdocs.jabref.org/code-howtos/#get-a-relative-filename-or-path-for-a-file

Use sub directory "assets" (make it a constant in JabRef, so that we could change later)

(Maybe you find another solution at the related feature #14330 , but I don't remember)

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 16, 2025
@ganesh-vk
Copy link
Copy Markdown
Contributor Author

ganesh-vk commented Dec 16, 2025

What are "all images types"?

For e.g. webp is not rendered correctly, but webp is an image format so FileUtil.isImage will return true for webp. I can remove webp and other unsupported types from StandardFileTypes but I didn't think that would be a good fix.

Currently all supported formats get rendered and the image gets saved in the directory specified in preferences.

Adding Steps to test and screenshots now, since the PR was incomplete and still a draft I didn't add them.

@github-actions github-actions bot added good second issue Issues that involve a tour of two or three interweaved components in JabRef and removed status: changes-required Pull requests that are not yet complete labels Dec 16, 2025
@ganesh-vk ganesh-vk marked this pull request as ready for review December 16, 2025 13:16
@ganesh-vk ganesh-vk requested a review from koppor December 16, 2025 14:08
Files.copy(file.toPath(), destination, StandardCopyOption.REPLACE_EXISTING);
String relativePath = FileUtil.relativize(destination, databaseContext.getFileDirectories(filePreferences)).toString();
String markdownText = "![](" + relativePath + ")\n";
textArea.appendText(markdownText);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to insert the link at the place where the mouse pointer was placed when the drop was triggered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to insert at caret position, I wasn't sure if it is better if it's pasted where the caret is compared to just appending since it might lead to formatting errors.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 17, 2025
@ganesh-vk ganesh-vk requested a review from koppor December 17, 2025 18:57
@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Dec 17, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Your pull request conflicts with the target branch.

Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 23, 2025

Note that I merged main to have JabRef starting again.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 23, 2025
CHANGELOG.md Outdated
### Added

- We added the ability to drag and drop images to the comments field. [14620](https://github.com/JabRef/jabref/pull/14620/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed)
- We added the ability to drag and drop images to the comments field. [#14620](https://github.com/JabRef/jabref/issues/10559)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? Are you sure???

Did you or your AI not perform? What time is it? I am awake since 17 hours and still see it.

Why are you doing this to us?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note #10559 is the right link and #10559 the right issue number

Suggested change
- We added the ability to drag and drop images to the comments field. [#14620](https://github.com/JabRef/jabref/issues/10559)
- We added the ability to drag and drop images to the comments field. [#10559](https://github.com/JabRef/jabref/issues/10559)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 4 AM, I'm sorry I missed that, only copy pasted the correct link and forgot to change that :)

}
}

layoutText = formatPreviewText(baseUrl, text);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an unsaved library no preview will ever be generated - why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

List<Path> fileDirList = databaseContext.getFileDirectories(filePreferences);
Path relativePath = FileUtil.relativize(file.toPath(), fileDirList);

// If the path is already relative, just insert the Markdown text
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the path is already relative, just insert the Markdown text
// If the path can be reached from the configured directories somehow, just insert the Markdown text

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 23, 2025
Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the follow up.

You are on Windows or Linux?

![](img\assignment.png)

Cannot be rendered here

![](img/'assignment.png)

can.

Any idea of a fix or should I do it?

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

Thank you for the follow up.

You are on Windows or Linux?

![](img\assignment.png)
``´

Cannot be rendered here


```markdown
![](img/'assignment.png)

can.

Any idea of a fix or should I do it?

I didn't understand, could you please elaborate?

I am using Linux (Fedora)
I've attached a video showcasing a weird bug I found, I cannot figure out what is causing it. Dragging and dropping files from the file manager seems to not work, but the same downloaded file from firefox works

Jabref-DragDropBug.mp4

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 23, 2025

I didn't understand, could you please elaborate?

result of drag and drop - no image shown

image

Change \ to /

image shown

image

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

Looks like this is a windows path problem, I will look into this tomorrow, do you have any hints on what I should try?

}

private void insertMarkdownText(String relativePath, EditorTextArea textArea) {
String markdownText = "![](" + relativePath + ")\n";
Copy link
Copy Markdown
Member

@Siedlerchr Siedlerchr Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markdown only understands forward / slashes! Backslash \ is an escape character. This might explain the path issue

https://www.markdownguide.org/basic-syntax/

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 23, 2025
@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 24, 2025

Looks like this is a windows path problem, I will look into this tomorrow, do you have any hints on what I should try?

replace \ by / in the path - locally in insertMarkdownText

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 24, 2025

Dragging and dropping files from the file manager seems to not work,

Welcome to the hell of drag and drop...

One "just" need to add LOGGERR.trace statements for the drag type, read the output, think etc... but I would postpone that for a follow-up. Basically, this will work (if the windows path issue is solved)

See https://devdocs.jabref.org/code-howtos/logging.html for loggin

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

Looks like this is a windows path problem, I will look into this tomorrow, do you have any hints on what I should try?

replace \ by / in the path - locally in insertMarkdownText

I've done this, could you please test it out in Windows and see if it works? I can't test this since I'm on linux

@koppor koppor added this pull request to the merge queue Dec 24, 2025
@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 24, 2025

@ganesh-vk Works well - thank you for the quick follow ups. This values our time.

@ganesh-vk
Copy link
Copy Markdown
Contributor Author

@ganesh-vk Works well - thank you for the quick follow ups. This values our time.

Thank you for the reviews!

Merged via the queue into JabRef:main with commit 865add7 Dec 24, 2025
49 checks passed
@ganesh-vk ganesh-vk deleted the markdown-dragdrop branch December 24, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: entry-editor good second issue Issues that involve a tour of two or three interweaved components in JabRef 📌 Pinned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow file attachment into the comments editor (Markdown)

4 participants