erossini / BlazorMarkdownEditor

Complete Markdown Editor component for Blazor WebAssembly and Blazor Server. Full of functionalities
https://www.puresourcecode.com/dotnet/blazor/markdown-editor-component-for-blazor/
MIT License
142 stars 22 forks source link

Custom button to insert text at cursor #36

Open deathau opened 4 months ago

deathau commented 4 months ago

The default button actions all add text where the cursor is (or at the beginning of the line). I was wondering if there was a way to achieve that with this component.

For a custom button, I can handle the CustomButtonClicked event, but I can't find a way to get the cursor position or anything to insert text, meaning I can only really append or prepend to the entire markdown text.

Alternately, is there a way I can add a JavaScript function as an action for my custom button? If I could do that, I could just do something like

<MarkdownToolbarButton Separator Name="Custom button" 
                         JSAction="(editor) => editor.codemirror.replaceSelection('Custom')"
                         Icon="fa fa-star" 
                         Title="A Custom Button" />

(as per https://github.com/Ionaru/easy-markdown-editor/issues/273#issuecomment-745909535)

erossini commented 2 months ago

I'll think about how I can add this functionality. Enrico

lbanobre commented 1 month ago

Hi @erossini, Maybe implementing insertTexts