Skip to content

Commit

Permalink
Insert image upload at cursor position.
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjaparade committed Aug 10, 2020
1 parent 8428d70 commit 04afd2e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions resources/js/components/MarkdownEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
textarea: null,
content: "",
uploadProgress: 0,
uploading: false
};
},
Expand All @@ -37,7 +38,7 @@ export default {
this.textarea.style.height =
Math.min(this.textarea.scrollHeight, heightLimit) + "px";
this.textarea.oninput = function() {
this.textarea.oninput = () => {
this.textarea.style.height = "";
this.textarea.style.height =
Math.min(this.textarea.scrollHeight, heightLimit) +
Expand Down Expand Up @@ -76,7 +77,7 @@ export default {
const placeholder = `![Uploading ${image.name}…]()`;
this.content = this.content.concat(placeholder);
this.insertAtCursor(placeholder);
this.http()
.post("/api/uploads", formData, {
Expand All @@ -93,6 +94,13 @@ export default {
console.log(error);
});
},
insertAtCursor(text) {
this.textarea.focus();
document.execCommand("insertText", false /*no UI*/, text);
this.content = this.textarea.value;
},
insertImage(placeholder, url) {
this.content = this.content.replace(
placeholder,
Expand Down

0 comments on commit 04afd2e

Please sign in to comment.