fix: Insert asset filename as link text when dropping a non-image asset without a selection#78
Open
patrickbitzer wants to merge 1 commit into
Open
fix: Insert asset filename as link text when dropping a non-image asset without a selection#78patrickbitzer wants to merge 1 commit into
patrickbitzer wants to merge 1 commit into
Conversation
Dropping a non-image asset (e.g. PDF, DOCX) into a Quill WYSIWYG
without a prior text selection produced no visible output. The
onDropWysiwyg handler called quill.format('link', uri) only, which
per Quill's API sets a "next character" format on an empty
selection but does not insert any text — leaving the editor
unchanged. The follow-up getLeaf() lookup then never found an <a>,
so pimcore_id and pimcore_type were also missing.
When no text is selected, insert the asset filename (data.text
with a path-derived fallback) as plain text and select it; the
existing link-formatting and pimcore_id / pimcore_type attribute
logic then applies as it does for the selected-text case. The
image-drop path and the document/object branches are untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a non-image asset (e.g. PDF, DOCX, video) is dragged from the asset tree into a Quill WYSIWYG editor without an existing text selection, nothing visible is inserted. No link, no text — the drop appears to be a no-op to the user.
This is a regression compared to the legacy CKEditor-based WYSIWYG, where dropping the same asset inserted the asset's filename as a clickable link automatically.
Steps to reproduce
pimcore/quill-bundle.Expected behavior
The asset filename is inserted as a clickable link at the drop position, with the
pimcore_idandpimcore_type="asset"attributes set on the resulting<a>element — matching the behavior of the legacy CKEditor integration as well as the existing behavior for image assets (which are inserted as<img>).Actual behavior
Nothing visible happens. The cursor remains at its previous position and no markup is added to the editor.
Root cause
In
public/js/editor.js, theonDropWysiwyghandler distinguishes only two cases for assets:The
elsebranch handles both "asset with selection" and "non-image asset without selection" identically. It callsthis.activeEditor.format('link', uri), which — per Quill's API — only applies a format to the currently selected range. If the selection is empty (length 0),format()sets a "next character" format on the cursor but does not insert any text. Subsequently,getLeaf(retval.index + 1)cannot find an<a>element, sopimcore_idandpimcore_typeare never set either.For images this is already explicitly handled (
insertEmbed), but for all other asset types the empty-selection path is missing.Proposed fix
If no text is selected when a non-image asset is dropped, first insert the asset's filename as plain text, select it, and let the existing link-formatting code take over:
data.textis the value already used by the bundle for file-extension detection at line 212 (pimcore.helpers.getFileExtension(data.text)), and corresponds to the filename as shown in the asset tree (e.g.brochure.pdf).data.path.split('/').pop()is used as a defensive fallback in casedata.textis not populated.'Datei'is a final fallback so an empty<a>is never produced. Maintainers may want to replace this with a translation key — happy to adjust.Behavior after the fix
<img>pimcore_id/pimcore_type="asset"Notes for reviewers
pimcore/quill-bundle2.2.x against PDF, DOCX, MP4 and SVG (non-rasterized) assets.Environment
pimcore/admin-ui-classic-bundle: 2.2.xpimcore/quill-bundle: 2.2.x