This commit is contained in:
@@ -106,12 +106,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateSelectedRange() {
|
getSelectedRange() {
|
||||||
let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
let bodyTextArea = this.$refs.editArea.$el.querySelector("textarea");
|
||||||
this.selection.start = bodyTextArea.selectionStart;
|
this.selection.start = bodyTextArea.selectionStart;
|
||||||
this.selection.end = bodyTextArea.selectionEnd;
|
this.selection.end = bodyTextArea.selectionEnd;
|
||||||
this.selection.hasSelection = this.selection.start != this.selection.end;
|
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() {
|
getSelectedText() {
|
||||||
let selectedText = "";
|
let selectedText = "";
|
||||||
if (this.selection.hasSelection) {
|
if (this.selection.hasSelection) {
|
||||||
@@ -142,21 +146,22 @@ export default {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
clickBold() {
|
clickBold() {
|
||||||
this.updateSelectedRange();
|
this.getSelectedRange();
|
||||||
this.replaceSelectedText("**" + this.getSelectedText() + "**");
|
this.replaceSelectedText("**" + this.getSelectedText() + "**");
|
||||||
//console.log("BOLD CLICK, selection:", this.getSelectedText());
|
//console.log("BOLD CLICK, selection:", this.getSelectedText());
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDoubleClick(i) {
|
handleDoubleClick(i) {
|
||||||
//the purpose of this is only to change the selection if it's got an extra space to the right
|
//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
|
//because double clicking on a word with another word after it causes the space to be included
|
||||||
this.updateSelectedRange();
|
this.getSelectedRange();
|
||||||
let temp = this.getSelectedText();
|
let temp = this.getSelectedText();
|
||||||
let tempTrimmed = temp.trimEnd();
|
let tempTrimmed = temp.trimEnd();
|
||||||
let diff = temp.length - tempTrimmed.length;
|
let diff = temp.length - tempTrimmed.length;
|
||||||
if (diff != 0) {
|
if (diff != 0) {
|
||||||
//there were some spaces so update the selection range
|
//there were some spaces so update the selection range
|
||||||
//force selection to be shorter by diff
|
//force selection to be shorter by diff
|
||||||
|
this.setSelectedRange(this.selection.start, this.selection.end - diff);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleInput(val) {
|
handleInput(val) {
|
||||||
|
|||||||
Reference in New Issue
Block a user