From 12da3c4780be2dc70e4f90115bb5319131b31e58 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 17 Apr 2020 20:17:29 +0000 Subject: [PATCH] --- ayanova/src/components/wiki-control.vue | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ayanova/src/components/wiki-control.vue b/ayanova/src/components/wiki-control.vue index 36c31f6b..f4535241 100644 --- a/ayanova/src/components/wiki-control.vue +++ b/ayanova/src/components/wiki-control.vue @@ -106,12 +106,16 @@ export default { } }, methods: { - updateSelectedRange() { + getSelectedRange() { let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea"); this.selection.start = bodyTextArea.selectionStart; this.selection.end = bodyTextArea.selectionEnd; this.selection.hasSelection = this.selection.start != this.selection.end; }, + setSelectedRange(start, end) { + let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea"); + bodyTextArea.setSelectionRange(start, end); + }, getSelectedText() { let selectedText = ""; if (this.selection.hasSelection) { @@ -142,21 +146,22 @@ export default { ); }, clickBold() { - this.updateSelectedRange(); + this.getSelectedRange(); this.replaceSelectedText("**" + this.getSelectedText() + "**"); //console.log("BOLD CLICK, selection:", this.getSelectedText()); }, handleDoubleClick(i) { //the purpose of this is only to change the selection if it's got an extra space to the right - //becuase double clicking on a word with another word after it causes the space to be included - this.updateSelectedRange(); + //because double clicking on a word with another word after it causes the space to be included + this.getSelectedRange(); let temp = this.getSelectedText(); let tempTrimmed = temp.trimEnd(); let diff = temp.length - tempTrimmed.length; if (diff != 0) { //there were some spaces so update the selection range //force selection to be shorter by diff + this.setSelectedRange(this.selection.start, this.selection.end - diff); } }, handleInput(val) {