A platform for community discussion. Free, open, simple.
FIX: Fit both faces of a preview block to its frame (#43087)
Renato Atilioae0020c69b80
diff --git a/app/assets/stylesheets/common/rich-editor/rich-editor.scss b/app/assets/stylesheets/common/rich-editor/rich-editor.scssindex a98c7ceff1c..80a3257670c 100644--- a/app/assets/stylesheets/common/rich-editor/rich-editor.scss+++ b/app/assets/stylesheets/common/rich-editor/rich-editor.scss@@ -351,6 +351,11 @@> * {grid-area: 1 / 1;++ // a face fits the block and scrolls its own overflow, rather than+ // sizing the shared cell to fit its content+ min-width: 0;+ min-height: 0;}&.ProseMirror-selectednode {@@ -365,9 +370,10 @@visibility: hidden;}- // a long source scrolls within a bounded face instead of growing the block+ // a long source scrolls within a bounded face instead of growing the block.+ // A preview that frames itself overrides the bound to match that frame.&__source {- max-height: 14lh;+ max-height: var(--composer-preview-node-source-max-height, 14lh);}&__source pre {diff --git a/frontend/discourse/tests/integration/components/prosemirror-editor/preview-node-view-test.gjs b/frontend/discourse/tests/integration/components/prosemirror-editor/preview-node-view-test.gjsindex 35329def4ad..8a15733fda3 100644--- a/frontend/discourse/tests/integration/components/prosemirror-editor/preview-node-view-test.gjs+++ b/frontend/discourse/tests/integration/components/prosemirror-editor/preview-node-view-test.gjs@@ -193,6 +193,24 @@ module();});+ test("keeps a long source line inside the block", async function (assert) {+ const [editorClass] = await setupRichEditor(assert, "");+ await insertBlock(editorClass.view, "x".repeat(400));+ await toggleSource(editorClass.view);++ const block = document.querySelector(".composer-preview-node");+ const source = document.querySelector(".composer-preview-node__source");++ assert.true(+ source.clientWidth <= block.clientWidth,+ "the source face stays within the block rather than widening it"+ );+ assert.true(+ block.clientWidth <= block.parentElement.clientWidth,+ "so the block stays within the editor"+ );+ });+test("renders again when the source changes under a shown preview", async function (assert) {const [editorClass] = await setupRichEditor(assert, "");await insertBlock(editorClass.view, "before");diff --git a/plugins/discourse-graphviz/assets/stylesheets/common/graphviz.scss b/plugins/discourse-graphviz/assets/stylesheets/common/graphviz.scssindex 7b0e6bccabc..c4e62e3c795 100644--- a/plugins/discourse-graphviz/assets/stylesheets/common/graphviz.scss+++ b/plugins/discourse-graphviz/assets/stylesheets/common/graphviz.scss@@ -11,10 +11,11 @@ div.graphviz.is-loading,}}-// Match the cooked diagram frame and keep long source inside it.+// The block frames the diagram as the cooked wrapper does, so both faces fit+// that frame and scroll whatever does not fit inside it..composer-graphviz-node {+ --composer-preview-node-source-max-height: 100%;aspect-ratio: 16 / 9;- min-height: 3em;}// Hide the raw DOT source until the client replaces the placeholder.diff --git a/plugins/discourse-graphviz/test/javascripts/integration/rich-editor-extension-test.js b/plugins/discourse-graphviz/test/javascripts/integration/rich-editor-extension-test.jsindex 0a06e2c9d71..0154e33226a 100644--- a/plugins/discourse-graphviz/test/javascripts/integration/rich-editor-extension-test.js+++ b/plugins/discourse-graphviz/test/javascripts/integration/rich-editor-extension-test.js@@ -56,14 +56,25 @@ module(test("constrains a diagram with tall source", async function (assert) {await setupRichEditor(assert, TALL_GRAPH);- const { height, width } = find(- ".composer-graphviz-node"- ).getBoundingClientRect();+ const block = find(".composer-graphviz-node");+ const source = find(".composer-preview-node__source");+ const pre = source.querySelector("pre");+ const { height, width } = block.getBoundingClientRect();assert.true(Math.abs(height / width - 9 / 16) < 0.01,"the diagram uses the same aspect ratio as its cooked preview");++ assert.true(+ Math.abs(source.clientHeight - block.clientHeight) <= 1,+ "the source face fills the frame, neither overflowing nor falling short"+ );++ assert.true(+ pre.scrollHeight > pre.clientHeight,+ "the source scrolls within the frame"+ );});test("puts the caret in the source of a diagram it just inserted", async function (assert) {