Ionaru / Ionaru/easy-markdown-editor

Add ability to show custom dialogs

Open
#402 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.1k
Forks
363
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
Instead of the simple `prompt`-Dialog, I want to show my own dialog at least for links and images.

**Describe the solution you'd like**
The option `promptTexts` could be extended to allow a function, too.
If you treat the functions return value as promise, the solution could be easily done with something like

```js
function drawLink(editor) {
var cm = editor.codemirror;
var stat = getState(cm);
var options = editor.options;
var url = 'https://';
var text = options.insertTexts.link;
var promptResult;

if (options.promptURLs) {
var promptText = options.promptTextslink;
if (typeof promptText === 'function') {
promptResult = promptOption(type);
} else {
promptResult = prompt(promptOption, url);
}
} else {
promptResult = url;
}

Promise.resolve(promptResult)
.then(function (url) {
drawLinkFinally(editor, url)
})
.catch(function () {});
}

function drawLinkFinal(editor, url) {
var cm = editor.codemirror;
var stat = getState(cm);
var options = editor.options;

if (!url) {
return false;
}

url = escapePromptURL(url);
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
}
```

If you don't want to depend upon `Promise`, you can detect if there's a `then`-function on the result and use it that way, or (if the `then` function is missing) use the `drawLinkOrImageFinal` directly.

**Additional context**
It would be great, if the `_replaceSelection` would not only replace `#url#` from a string, but all object values of a map.
If you e.g. use `{ url: "https://xyz", linkText: "My URL" }` instead of a string, and the insertTexts-pattern is `[#linkText#](#url#)`, you can have much more complex dialogs.
`escapePromptURL` must be aware in that case, too..

Contributor guide

Open the contributing guide

Research direction

Start by tracing the link and image dialog flow around promptTexts, drawLink, and drawLinkFinally. Inspect _replaceSelection and escapePromptURL to understand the existing string-only behavior. Done means custom synchronous or promise-based dialogs work for links and images, and object values can populate insertTexts patterns without breaking URL escaping.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.