From 6a60598caaf1fd771b6efe45a22f9fc39dcd91b2 Mon Sep 17 00:00:00 2001 From: jedi Date: Wed, 22 May 2024 23:49:13 +0200 Subject: [PATCH] stash --- web/src/components/inputs/FormatedText.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web/src/components/inputs/FormatedText.vue b/web/src/components/inputs/FormatedText.vue index be4326c..9aaf592 100644 --- a/web/src/components/inputs/FormatedText.vue +++ b/web/src/components/inputs/FormatedText.vue @@ -1,5 +1,5 @@ @@ -17,6 +17,11 @@ export default { default: null } }, + data() { + return { + selection: null, + }; + }, emits: ['input'], methods: { rawhtml(value) { @@ -27,8 +32,21 @@ export default { } }, onchange(event) { + this.selection = window.getSelection(); this.$emit('input', event.target.innerText); } + }, + watch: { + value() { + if (this.selection) { + const div = this.$refs.text; + const range = document.createRange(); + range.setStart(div.childNodes[0], this.selection.anchorOffset); + range.setEnd(div.childNodes[0], this.selection.focusOffset); + this.selection.removeAllRanges(); + this.selection.addRange(range); + } + } } }; \ No newline at end of file