Skip to content

Commit 04afd2e

Browse files
authored
Insert image upload at cursor position.
1 parent 8428d70 commit 04afd2e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

resources/js/components/MarkdownEditor.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
textarea: null,
1515
content: "",
1616
uploadProgress: 0,
17+
uploading: false
1718
};
1819
},
1920
@@ -37,7 +38,7 @@ export default {
3738
this.textarea.style.height =
3839
Math.min(this.textarea.scrollHeight, heightLimit) + "px";
3940
40-
this.textarea.oninput = function() {
41+
this.textarea.oninput = () => {
4142
this.textarea.style.height = "";
4243
this.textarea.style.height =
4344
Math.min(this.textarea.scrollHeight, heightLimit) +
@@ -76,7 +77,7 @@ export default {
7677
7778
const placeholder = `![Uploading ${image.name}…]()`;
7879
79-
this.content = this.content.concat(placeholder);
80+
this.insertAtCursor(placeholder);
8081
8182
this.http()
8283
.post("/api/uploads", formData, {
@@ -93,6 +94,13 @@ export default {
9394
console.log(error);
9495
});
9596
},
97+
98+
insertAtCursor(text) {
99+
this.textarea.focus();
100+
101+
document.execCommand("insertText", false /*no UI*/, text);
102+
this.content = this.textarea.value;
103+
},
96104
insertImage(placeholder, url) {
97105
this.content = this.content.replace(
98106
placeholder,

0 commit comments

Comments
 (0)