Skip to content

Commit 5d8573b

Browse files
authored
Fix image node update in applyExternalChanges (#70)
Fix pasted image not displayed when using applyExternalChanges
1 parent df20981 commit 5d8573b

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/core/commands.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ export function touchCitations() {
465465
&& node.attrs.annotation && node.attrs.annotation.citationItem) {
466466
tr.setNodeMarkup(pos, null, { ...node.attrs, version: (node.attrs.version || 0) + 1 });
467467
}
468+
else if (node.type === schema.nodes.image && node.attrs.attachmentKey) {
469+
tr.setNodeMarkup(pos, null, { ...node.attrs, version: (node.attrs.version || 0) + 1 });
470+
}
468471
});
469472
tr.setMeta('addToHistory', false);
470473
tr.setMeta('system', true);

src/core/node-views/image.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ class ImageView {
164164
if (node.type !== this.node.type) {
165165
return false;
166166
}
167+
168+
if (node.attrs.version !== this.node.attrs.version ||
169+
node.attrs.attachmentKey !== this.node.attrs.attachmentKey ||
170+
node.attrs.src !== this.node.attrs.src ||
171+
node.attrs.nodeID !== this.node.attrs.nodeID) {
172+
return false;
173+
}
174+
175+
// Make sure the newly created image uses correct dimensions
176+
if (node.attrs.attachmentKey && (node.attrs.width !== this.node.attrs.width || node.attrs.height !== this.node.attrs.height)) {
177+
let resizedWrapper = this.dom.querySelector('.resized-wrapper');
178+
if (resizedWrapper) {
179+
if (node.attrs.width !== null) {
180+
resizedWrapper.style.width = node.attrs.width + 'px';
181+
}
182+
else {
183+
resizedWrapper.style.width = '';
184+
}
185+
}
186+
}
187+
167188
this.node = node;
168189
this.updateCitation();
169190
return true;

0 commit comments

Comments
 (0)