Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: fix code editor scrolling (#2972)

Bogdan Chadkin75a42a4b4cfc
diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsx
index 98133fcb2a..15d0249590 100644
--- a/apps/builder/app/builder/shared/code-editor.tsx
+++ b/apps/builder/app/builder/shared/code-editor.tsx
@@ -56,14 +56,18 @@ const editorContentStyle = css({
},
"& .cm-content": {
padding: 0,
+ // makes sure you can click to focus when editor content is smaller than the container
+ minHeight: "100%",
},
"& .cm-line": {
padding: 0,
},
"& .cm-editor": {
width: "100%",
- // makes sure you can click to focus when editor content is smaller than the container
- height: "100%",
+ // avoid modifying height in .cm-content
+ // because it breaks scroll events and makes scrolling laggy
+ minHeight: "var(--ws-code-editor-min-height, auto)",
+ maxHeight: "var(--ws-code-editor-max-height, none)",
},
});
diff --git a/apps/builder/app/builder/shared/expression-editor.tsx b/apps/builder/app/builder/shared/expression-editor.tsx
index edf1dea500..c722dd4686 100644
--- a/apps/builder/app/builder/shared/expression-editor.tsx
+++ b/apps/builder/app/builder/shared/expression-editor.tsx
@@ -341,11 +341,9 @@ const emptyScope: Scope = {};
const emptyAliases: Aliases = new Map();
const wrapperStyle = css({
- "& .cm-content": {
- // 1 line is 16px
- // set and max 20 lines
- maxHeight: 320,
- },
+ // 1 line is 16px
+ // set and max 20 lines
+ "--ws-code-editor-max-height": "320px",
});
export const ExpressionEditor = ({
diff --git a/apps/builder/app/builder/shared/html-editor.tsx b/apps/builder/app/builder/shared/html-editor.tsx
index def46fc4e3..6ce565b4a3 100644
--- a/apps/builder/app/builder/shared/html-editor.tsx
+++ b/apps/builder/app/builder/shared/html-editor.tsx
@@ -68,12 +68,10 @@ const autocompletionStyle = css({
const wrapperStyle = css({
position: "relative",
- "& .cm-content": {
- // 1 line is 16px
- // set min 10 lines and max 20 lines
- minHeight: 160,
- maxHeight: 320,
- },
+ // 1 line is 16px
+ // set min 10 lines and max 20 lines
+ "--ws-code-editor-min-height": "160px",
+ "--ws-code-editor-max-height": "320px",
});
export const HtmlEditor = forwardRef<