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: code editor bugs (#2829)

Bogdan Chadkin281678460229
diff --git a/apps/builder/app/builder/shared/binding-popover.tsx b/apps/builder/app/builder/shared/binding-popover.tsx
index cb139d7e22..54e4f0d7ee 100644
--- a/apps/builder/app/builder/shared/binding-popover.tsx
+++ b/apps/builder/app/builder/shared/binding-popover.tsx
@@ -244,14 +244,14 @@ const bindingOpacityProperty = "--ws-binding-opacity";
export const BindingControl = ({ children }: { children: ReactNode }) => {
return (
- <Flex
+ <Box
css={{
position: "relative",
"&:hover": { [bindingOpacityProperty]: 1 },
}}
>
{children}
- </Flex>
+ </Box>
);
};
diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsx
index 214644d724..a28e09849d 100644
--- a/apps/builder/app/builder/shared/code-editor.tsx
+++ b/apps/builder/app/builder/shared/code-editor.tsx
@@ -28,6 +28,10 @@ const rootStyle = css({
"& .cm-focused": {
outline: "none",
},
+ // fix scrolls appear on mount
+ "& .cm-scroller": {
+ overflowX: "hidden",
+ },
"& .cm-content": {
padding: 0,
},
@@ -90,6 +94,7 @@ export const CodeEditor = ({
view.dispatch({
effects: StateEffect.reconfigure.of([
...extensions,
+ EditorView.lineWrapping,
EditorView.editable.of(readOnly === false),
EditorState.readOnly.of(readOnly === true),
// https://github.com/uiwjs/react-codemirror/blob/5d7a37245ce70e61f215b77dc42a7eaf295c46e7/core/src/useCodeMirror.ts#L57-L70
diff --git a/apps/builder/app/builder/shared/expression-editor.tsx b/apps/builder/app/builder/shared/expression-editor.tsx
index 92a48585dd..a73ae3ad97 100644
--- a/apps/builder/app/builder/shared/expression-editor.tsx
+++ b/apps/builder/app/builder/shared/expression-editor.tsx
@@ -211,6 +211,14 @@ const autocompletionStyle = css({
const emptyScope: Scope = {};
const emptyAliases: Aliases = new Map();
+const wrapperStyle = css({
+ "& .cm-content": {
+ // 1 line is 16px
+ // set and max 20 lines
+ maxHeight: 320,
+ },
+});
+
const errorStyle = css({
borderColor: theme.colors.borderDestructiveMain,
});
@@ -247,7 +255,6 @@ export const ExpressionEditor = ({
dropCursor(),
bracketMatching(),
closeBrackets(),
- EditorView.lineWrapping,
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
javascript({}),
VariablesData.of({ scope, aliases }),
@@ -278,14 +285,16 @@ export const ExpressionEditor = ({
);
return (
- <CodeEditor
- extensions={extensions}
- className={color === "error" ? errorStyle.toString() : undefined}
- readOnly={readOnly}
- autoFocus={autoFocus}
- value={value}
- onChange={onChange}
- onBlur={onBlur}
- />
+ <div className={wrapperStyle.toString()}>
+ <CodeEditor
+ extensions={extensions}
+ className={color === "error" ? errorStyle.toString() : undefined}
+ readOnly={readOnly}
+ autoFocus={autoFocus}
+ value={value}
+ onChange={onChange}
+ onBlur={onBlur}
+ />
+ </div>
);
};
diff --git a/apps/builder/app/builder/shared/html-editor.tsx b/apps/builder/app/builder/shared/html-editor.tsx
index 367ff414aa..abebc8719a 100644
--- a/apps/builder/app/builder/shared/html-editor.tsx
+++ b/apps/builder/app/builder/shared/html-editor.tsx
@@ -3,7 +3,6 @@ import {
keymap,
drawSelection,
dropCursor,
- EditorView,
tooltips,
highlightSpecialChars,
highlightActiveLine,
@@ -95,7 +94,6 @@ export const HtmlEditor = ({
drawSelection(),
dropCursor(),
indentOnInput(),
- EditorView.lineWrapping,
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
html({}),
bracketMatching(),
diff --git a/packages/design-system/src/components/switch.tsx b/packages/design-system/src/components/switch.tsx
index c4e4f6390b..37d1da0cdd 100644
--- a/packages/design-system/src/components/switch.tsx
+++ b/packages/design-system/src/components/switch.tsx
@@ -17,10 +17,11 @@ const switchStyle = css({
height: theme.spacing[8],
borderRadius: theme.borderRadius.pill,
position: "relative",
+ verticalAlign: "middle",
// in Figma there's an extra container with a padding
// so we need a pseudo element
- padding: padding,
+ padding,
"&:before": {
content: "''",
position: "absolute",