diff --git a/public/js/app.js b/public/js/app.js index a4617f2..0524334 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -17753,7 +17753,7 @@ __webpack_require__.r(__webpack_exports__); }); if (!_this.keyIncluded) { - textarea.value += transcript + " "; + _this.insertAtCursor(textarea, transcript + " "); } else { _this.transcript = transcript; @@ -17764,6 +17764,23 @@ __webpack_require__.r(__webpack_exports__); } }; }); + }, + insertAtCursor: function insertAtCursor(myField, myValue) { + //IE support + if (document.selection) { + myField.focus(); + sel = document.selection.createRange(); + sel.text = myValue; + } //MOZILLA and others + else if (myField.selectionStart || myField.selectionStart == "0") { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); + myField.selectionStart = startPos + myValue.length; + myField.selectionEnd = startPos + myValue.length; + } else { + myField.value += myValue; + } } } }); @@ -19652,8 +19669,8 @@ var MarkdownTableButtonElement = /*#__PURE__*/function (_MarkdownButtonElemen8) _this9 = _super9.call(this); styles.set(_assertThisInitialized(_this9), { - prefix: "| Cool Header | Cool Header | \n", - suffix: "| ----------------- | ------------------ |\n| Content Cell | Content Cell |", + prefix: "| Cool Header | Cool Header |\n", + suffix: "| ------------ | ----------- |\n| Content | Content |", surroundWithNewlines: true }); return _this9; diff --git a/public/markdowntoolbar/index.d.ts b/public/markdowntoolbar/index.d.ts index 544ad43..127e676 100644 --- a/public/markdowntoolbar/index.d.ts +++ b/public/markdowntoolbar/index.d.ts @@ -16,7 +16,7 @@ declare global { MarkdownStrikethroughButtonElement: typeof MarkdownStrikethroughButtonElement; MarkdownTableButtonElement: typeof MarkdownTableButtonElement; MarkdownUnderlineButtonElement: typeof MarkdownUnderlineButtonElement; - MarkdownNextLineButtonElement: typeof MarkdownUnderlineButtonElement; + MarkdownNextLineButtonElement: typeof MarkdownNextLineButtonElement; } interface HTMLElementTagNameMap { "markdown-toolbar": MarkdownToolbarElement; diff --git a/public/markdowntoolbar/index.js b/public/markdowntoolbar/index.js index a8c0d6c..0b87688 100644 --- a/public/markdowntoolbar/index.js +++ b/public/markdowntoolbar/index.js @@ -161,8 +161,8 @@ class MarkdownTableButtonElement extends MarkdownButtonElement { constructor() { super(); styles.set(this, { - prefix: "| Cool Header | Cool Header | \n", - suffix: "| ----------------- | ------------------ |\n| Content Cell | Content Cell |", + prefix: "| Cool Header | Cool Header |\n", + suffix: "| ------------ | ----------- |\n| Content | Content |", surroundWithNewlines: true, }); } diff --git a/resources/js/components/Markdowntoolbar.vue b/resources/js/components/Markdowntoolbar.vue index 8b41ab5..507cda5 100644 --- a/resources/js/components/Markdowntoolbar.vue +++ b/resources/js/components/Markdowntoolbar.vue @@ -373,7 +373,7 @@ export default { }); if (!this.keyIncluded) { - textarea.value += transcript + " "; + this.insertAtCursor(textarea, transcript + " "); } else { this.transcript = transcript; this.vocalCommands(); @@ -383,6 +383,27 @@ export default { }; }); }, + insertAtCursor(myField, myValue) { + //IE support + if (document.selection) { + myField.focus(); + sel = document.selection.createRange(); + sel.text = myValue; + } + //MOZILLA and others + else if (myField.selectionStart || myField.selectionStart == "0") { + var startPos = myField.selectionStart; + var endPos = myField.selectionEnd; + myField.value = + myField.value.substring(0, startPos) + + myValue + + myField.value.substring(endPos, myField.value.length); + myField.selectionStart = startPos + myValue.length; + myField.selectionEnd = startPos + myValue.length; + } else { + myField.value += myValue; + } + }, }, };