This commit is contained in:
j3d1 2024-06-06 21:19:36 +02:00
parent 3a2a6328b0
commit 8f1cc0bba3

View file

@ -18,7 +18,7 @@ export default {
}, },
data() { data() {
return { return {
selection: {start: 0, end: 0} selection: {start: 0, end: 0, direction: 'forward', type: 'Caret'}
}; };
}, },
emits: ['input'], emits: ['input'],
@ -36,6 +36,8 @@ export default {
if (sel.rangeCount > 0) { if (sel.rangeCount > 0) {
this.selection.start = this.calculateOffset(div, sel.anchorNode, sel.anchorOffset); this.selection.start = this.calculateOffset(div, sel.anchorNode, sel.anchorOffset);
this.selection.end = this.calculateOffset(div, sel.focusNode, sel.focusOffset); this.selection.end = this.calculateOffset(div, sel.focusNode, sel.focusOffset);
this.selection.direction = sel.direction;
this.selection.type = sel.type;
} }
this.$emit('input', event.target.innerText); this.$emit('input', event.target.innerText);
}, },
@ -96,7 +98,10 @@ export default {
console.log(this.selection); console.log(this.selection);
range.setStart(...this.findNode(div, this.selection.start)); range.setStart(...this.findNode(div, this.selection.start));
range.setEnd(...this.findNode(div, this.selection.end)); range.setEnd(...this.findNode(div, this.selection.end));
console.log(range);
sel.addRange(range); sel.addRange(range);
sel.type = this.selection.type;
sel.direction = this.selection.direction;
//this.selection.removeAllRanges(); //this.selection.removeAllRanges();
//this.selection.addRange(range); //this.selection.addRange(range);
} }