fabianmichael / kirby-markdown-field

Super-sophisticated markdown editor for Kirby 3, community built.
Other
160 stars 14 forks source link

Adding file via button deletes the selected text #166

Closed francois-gm closed 1 year ago

francois-gm commented 1 year ago

Hello,

A client has remarked that when they want to add files (with the files button) by selecting a word/text (to create a 'files:' link), the selected word/text dissapears.

Let's say they select the word 'hello' within their text, then click on the file button, then choose a file (already uploaded), then what appears is

(file: myfile.png)

instead of

(file: myfile.png text: my text)

Kirby version: 3.8.3 Version of the markdown plugin: 2.1.1

I had a look at the subsequent releases of these but no mention of such a thing, so I was curious whether this is reproductible.

MathiasGmeiner commented 1 year ago

have a small fix for a specific part of this problem. If an existing file is selected (and not uploaded via the file dialog of the Kirby Markdown field), these changes will add the selected text to the link.

I've replaced the following code:

this.editor.insert(selected.map((file) => file.dragText).join("\n\n"));

with this code:

const file = selected[0];
const selection = this.editor.getSelection();
const text = selection.length > 0 ? selection : file.filename;
this.editor.insert(`(file: ${file.filename} text: ${text})`);

in src/components/Buttons/File.js add line 52.

fabianmichael commented 1 year ago

@MathiasGmeiner Sorry for not responding for so long, I just looked at you code and updated the behavior of the editor (see latest release). Thanks for your contribution! :-)