Skip to content

Commit 9581b30

Browse files
committed
fix: do not repeat the page content after updating page list
Keep an instance of the editor around as long as it does not change. Calling `new Editor(...)` whenever rerendering the `RichText` component resulted in multiple copies of the content piling up. Fixes #214
1 parent 8622cb6 commit 9581b30

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/components/Page/RichText.vue

+32-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="menubar-icons" />
66
</div>
77
<div v-if="!loading">
8-
<EditorContent
8+
<EditorContent v-if="editor"
99
class="editor__content"
1010
:editor="editor" />
1111
</div>
@@ -62,6 +62,7 @@ export default {
6262
return {
6363
loading: true,
6464
pageContent: null,
65+
editor: null,
6566
}
6667
},
6768
@@ -99,33 +100,6 @@ export default {
99100
return this.markdownit.render(this.pageContent)
100101
},
101102
102-
/**
103-
* @returns {object}
104-
*/
105-
editor() {
106-
return new Editor({
107-
editable: false,
108-
extensions: [
109-
new Heading(),
110-
new Code(),
111-
new Bold(),
112-
new Italic(),
113-
new Strike(),
114-
new HardBreak(),
115-
new HorizontalRule(),
116-
new BulletList(),
117-
new OrderedList(),
118-
new Blockquote(),
119-
new CodeBlock(),
120-
new ListItem(),
121-
new Link({
122-
openOnClick: true,
123-
}),
124-
new Image({ currentDirectory: this.currentDirectory }),
125-
],
126-
content: this.htmlContent,
127-
})
128-
},
129103
},
130104
131105
watch: {
@@ -154,12 +128,42 @@ export default {
154128
this.$emit('empty')
155129
}
156130
this.loading = false
131+
this.editor = this.createEditor()
157132
this.$nextTick(() => { this.$emit('ready') })
158133
} catch (e) {
159134
const { id } = this.currentPage
160135
console.error(`Failed to fetch content of page ${id}`, e)
161136
}
162137
},
138+
139+
/**
140+
* @returns {object}
141+
*/
142+
createEditor() {
143+
return new Editor({
144+
editable: false,
145+
extensions: [
146+
new Heading(),
147+
new Code(),
148+
new Bold(),
149+
new Italic(),
150+
new Strike(),
151+
new HardBreak(),
152+
new HorizontalRule(),
153+
new BulletList(),
154+
new OrderedList(),
155+
new Blockquote(),
156+
new CodeBlock(),
157+
new ListItem(),
158+
new Link({
159+
openOnClick: true,
160+
}),
161+
new Image({ currentDirectory: this.currentDirectory }),
162+
],
163+
content: this.htmlContent,
164+
})
165+
},
166+
163167
},
164168
}
165169
</script>

0 commit comments

Comments
 (0)