2022-11-26 11:43:28 -05:00
|
|
|
function getContentToInsert({html, markdown}) {
|
|
|
|
return markdown || html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {MarkdownEditor} editor
|
|
|
|
*/
|
|
|
|
export function listen(editor) {
|
2023-04-18 17:20:02 -04:00
|
|
|
window.$events.listen('editor::replace', eventContent => {
|
2022-11-26 11:43:28 -05:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.replaceContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
window.$events.listen('editor::append', eventContent => {
|
2022-11-26 11:43:28 -05:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.appendContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
window.$events.listen('editor::prepend', eventContent => {
|
2022-11-26 11:43:28 -05:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.prependContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
window.$events.listen('editor::insert', eventContent => {
|
2022-11-26 11:43:28 -05:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.insertContent(markdown);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.$events.listen('editor::focus', () => {
|
|
|
|
editor.actions.focus();
|
|
|
|
});
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|