Skip to content

Commit ede70d6

Browse files
authored
Update MarkdownEditor.vue
1 parent 04afd2e commit ede70d6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

resources/js/components/MarkdownEditor.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,24 @@ export default {
9898
insertAtCursor(text) {
9999
this.textarea.focus();
100100
101-
document.execCommand("insertText", false /*no UI*/, text);
102-
this.content = this.textarea.value;
101+
const isSuccessful = document.execCommand(
102+
"insertText",
103+
false,
104+
text
105+
);
106+
107+
// Firefox (non-standard method)
108+
if (!isSuccessful && typeof input.setRangeText === "function") {
109+
const start = input.selectionStart;
110+
input.setRangeText(text);
111+
// update cursor to be at the end of insertion
112+
input.selectionStart = input.selectionEnd = start + text.length;
113+
114+
// Notify any possible listeners of the change
115+
const e = document.createEvent("UIEvent");
116+
e.initEvent("input", true, false);
117+
input.dispatchEvent(e);
118+
}
103119
},
104120
insertImage(placeholder, url) {
105121
this.content = this.content.replace(

0 commit comments

Comments
 (0)