Skip to content

Commit 7628e9f

Browse files
committed
fix(preview): Further improvements
* Don't calculate preview options decorations in readonly editor * Check for changed nodeSize when checking for decoration changes * Rename `editor` to `$editor` in vue compontent, it's not reactive Signed-off-by: Jonas <jonas@freesources.org>
1 parent bc5ca91 commit 7628e9f

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/components/Editor/PreviewOptions.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default {
6868
type: Number,
6969
required: true,
7070
},
71-
editor: {
71+
$editor: {
7272
type: Object,
7373
required: true,
7474
},
@@ -82,11 +82,11 @@ export default {
8282
8383
methods: {
8484
onOpen() {
85-
this.editor.commands.hideLinkBubble()
85+
this.$editor.commands.hideLinkBubble()
8686
},
8787
toggle(type) {
8888
this.open = false
89-
const chain = this.editor.chain().focus()
89+
const chain = this.$editor.chain().focus()
9090
.setTextSelection(this.offset + 1)
9191
if (type === 'text-only') {
9292
chain.unsetPreview().run()
@@ -95,7 +95,7 @@ export default {
9595
chain.setPreview().run()
9696
},
9797
deleteNode() {
98-
this.editor.commands.deleteRange({
98+
this.$editor.commands.deleteRange({
9999
from: this.offset,
100100
to: this.offset + this.nodeSize,
101101
})

src/plugins/headingAnchor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default function headingAnchor() {
2222

2323
state: {
2424
init(_, { doc }) {
25-
console.debug('headingAnchor init')
2625
const headings = extractHeadings(doc)
2726
return {
2827
headings,

src/plugins/previewOptions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export default function previewOptions({ editor }) {
2626

2727
state: {
2828
init(_, { doc }) {
29+
if (!editor.options.editable) {
30+
return { decorations: DecorationSet.create() }
31+
}
2932
const linkParagraphs = extractLinkParagraphs(doc)
3033
return {
3134
linkParagraphs,
@@ -36,6 +39,9 @@ export default function previewOptions({ editor }) {
3639
if (!tr.docChanged) {
3740
return value
3841
}
42+
if (!editor.options.editable) {
43+
return value
44+
}
3945
const linkParagraphs = extractLinkParagraphs(newState.doc)
4046
const decorations = mapDecorations(value, tr, linkParagraphs) || linkParagraphDecorations(newState.doc, linkParagraphs, editor)
4147
return { linkParagraphs, decorations }
@@ -96,6 +102,7 @@ function linkParagraphsChanged(current, prev) {
96102
*/
97103
const isDifferentFrom = (other) => (linkParagraph, i) => {
98104
return linkParagraph.type !== other[i].type
105+
|| linkParagraph.nodeSize !== other[i].nodeSize
99106
}
100107

101108
/**
@@ -138,7 +145,7 @@ function decorationForLinkParagraph(linkParagraph, editor) {
138145
*/
139146
function previewOptionForLinkParagraph(linkParagraph, editor) {
140147
const propsData = {
141-
editor,
148+
$editor: editor,
142149
...linkParagraph,
143150
}
144151
const el = document.createElement('div')

0 commit comments

Comments
 (0)