Skip to content

Commit

Permalink
fix(preview): Further improvements
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mejo- committed Sep 18, 2024
1 parent bc5ca91 commit 7628e9f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/Editor/PreviewOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
type: Number,
required: true,
},
editor: {
$editor: {
type: Object,
required: true,
},
Expand All @@ -82,11 +82,11 @@ export default {
methods: {
onOpen() {
this.editor.commands.hideLinkBubble()
this.$editor.commands.hideLinkBubble()
},
toggle(type) {
this.open = false
const chain = this.editor.chain().focus()
const chain = this.$editor.chain().focus()
.setTextSelection(this.offset + 1)
if (type === 'text-only') {
chain.unsetPreview().run()
Expand All @@ -95,7 +95,7 @@ export default {
chain.setPreview().run()
},
deleteNode() {
this.editor.commands.deleteRange({
this.$editor.commands.deleteRange({
from: this.offset,
to: this.offset + this.nodeSize,
})
Expand Down
1 change: 0 additions & 1 deletion src/plugins/headingAnchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function headingAnchor() {

state: {
init(_, { doc }) {
console.debug('headingAnchor init')
const headings = extractHeadings(doc)
return {
headings,
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/previewOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default function previewOptions({ editor }) {

state: {
init(_, { doc }) {
if (!editor.options.editable) {
return { decorations: DecorationSet.create() }
}
const linkParagraphs = extractLinkParagraphs(doc)
return {
linkParagraphs,
Expand All @@ -36,6 +39,9 @@ export default function previewOptions({ editor }) {
if (!tr.docChanged) {
return value
}
if (!editor.options.editable) {
return value
}
const linkParagraphs = extractLinkParagraphs(newState.doc)
const decorations = mapDecorations(value, tr, linkParagraphs) || linkParagraphDecorations(newState.doc, linkParagraphs, editor)
return { linkParagraphs, decorations }
Expand Down Expand Up @@ -96,6 +102,7 @@ function linkParagraphsChanged(current, prev) {
*/
const isDifferentFrom = (other) => (linkParagraph, i) => {
return linkParagraph.type !== other[i].type
|| linkParagraph.nodeSize !== other[i].nodeSize
}

/**
Expand Down Expand Up @@ -138,7 +145,7 @@ function decorationForLinkParagraph(linkParagraph, editor) {
*/
function previewOptionForLinkParagraph(linkParagraph, editor) {
const propsData = {
editor,
$editor: editor,
...linkParagraph,
}
const el = document.createElement('div')
Expand Down

0 comments on commit 7628e9f

Please sign in to comment.