Skip to content

Commit b4aa20b

Browse files
committed
fix(texteditor)[image]:limit saved dimensions compared to editor width
1 parent a17b386 commit b4aa20b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/image

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/image/ImageNodeView.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@
122122
if (imageRef.value && imageRef.value.naturalWidth && imageRef.value.naturalHeight) {
123123
naturalAspectRatio.value = imageRef.value.naturalWidth / imageRef.value.naturalHeight;
124124
125-
// If no dimensions are set, use natural dimensions
125+
// If no dimensions are set, use natural dimensions but constrain to editor width
126126
if (!width.value && !height.value) {
127-
width.value = imageRef.value.naturalWidth;
128-
height.value = imageRef.value.naturalHeight;
127+
// Get the editor's actual container width
128+
const editorContainer = props.editor.view.dom.closest('.editor-container');
129+
const editorWidth = editorContainer ? editorContainer.offsetWidth : 800; // fallback width
130+
131+
const maxWidth = Math.min(imageRef.value.naturalWidth, editorWidth);
132+
133+
width.value = maxWidth;
134+
height.value = Math.round(maxWidth / naturalAspectRatio.value);
135+
129136
saveSize();
130137
} else if (width.value && !height.value) {
131138
// If we have width but no height, calculate height

0 commit comments

Comments
 (0)