From 782eb29aacfa4dbc6b6cd935862b6c748cb60bad Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 20 Sep 2020 00:57:09 -0400 Subject: [PATCH] Fixed url-field bug with caret reset due to v-model update --- components/ui/url-field.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/ui/url-field.vue b/components/ui/url-field.vue index cf73a6c59..96140648e 100644 --- a/components/ui/url-field.vue +++ b/components/ui/url-field.vue @@ -22,6 +22,7 @@ export default { }, data() { return { + cacheValue: null, unwatchValue: null, } }, @@ -29,10 +30,13 @@ export default { this.$refs.editor.addEventListener("input", this.updateEditor) this.$refs.editor.textContent = this.value || "" + this.cacheValue = this.value || "" + this.unwatchValue = this.$watch( () => this.value, (newVal) => { - if (this.$refs.editor) this.$refs.editor.textContent = newVal || "" + if (this.$refs.editor && this.cacheValue !== newVal) + this.$refs.editor.textContent = newVal || "" this.updateEditor() } ) @@ -117,6 +121,8 @@ export default { sel.setBaseAndExtent(anchorNode, anchorIndex, focusNode, focusIndex) }, updateEditor() { + this.cacheValue = this.$refs.editor.textContent + const sel = window.getSelection() const textSegments = this.getTextSegments(this.$refs.editor) const textContent = textSegments.map(({ text }) => text).join("")