Skip to content

Commit 2a21fc7

Browse files
authored
fix: Optionally memorize min height in style panel advanced css editor (#4962)
[Discussion](https://discord.com/channels/955905230107738152/1347444065402224691) ## Description When advanced css editor is used in the style panel, we are avoiding jumps by preserving the scroll height, but in advanced mode when there is no parent scroll - we don't need that, so we can avoid blank space scrollbar. ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 6a453b9 commit 2a21fc7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getDots } from "../../shared/style-section";
2222
import { CssEditor, type CssEditorApi } from "../../../../shared/css-editor";
2323
import { $advancedStylesLonghands } from "./stores";
2424
import { $selectedInstanceKey } from "~/shared/awareness";
25+
import { getSetting } from "~/builder/shared/client-settings";
2526

2627
// Only here to keep the same section module interface
2728
export const properties = [];
@@ -141,6 +142,7 @@ export const Section = () => {
141142
onDeleteAllDeclarations={handleDeleteAllDeclarations}
142143
apiRef={apiRef}
143144
recentProperties={recentProperties}
145+
memorizeMinHeight={getSetting("stylePanelMode") !== "advanced"}
144146
/>
145147
</AdvancedStyleSection>
146148
);

apps/builder/app/builder/shared/css-editor/css-editor.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export const CssEditor = ({
319319
apiRef,
320320
showSearch = true,
321321
recentProperties = [],
322+
memorizeMinHeight = true,
322323
}: {
323324
onDeleteProperty: DeleteProperty;
324325
onSetProperty: SetProperty;
@@ -327,6 +328,9 @@ export const CssEditor = ({
327328
styleMap: CssStyleMap;
328329
apiRef?: RefObject<CssEditorApi>;
329330
showSearch?: boolean;
331+
// When used as part of some larger scroll area to avoid scroll jumps during search.
332+
// For example advanced section in the style panel.
333+
memorizeMinHeight?: boolean;
330334
recentProperties?: Array<CssProperty>;
331335
}) => {
332336
const [isAdding, setIsAdding] = useState(false);
@@ -354,10 +358,6 @@ export const CssEditor = ({
354358
const showRecentProperties =
355359
recentProperties.length > 0 && searchProperties === undefined;
356360

357-
const memorizeMinHeight = () => {
358-
setMinHeight(containerRef.current?.getBoundingClientRect().height ?? 0);
359-
};
360-
361361
const handleInsertStyles = (cssText: string) => {
362362
const styleMap = parseStyleInput(cssText);
363363
if (styleMap.size === 0) {
@@ -386,7 +386,9 @@ export const CssEditor = ({
386386
return handleAbortSearch();
387387
}
388388

389-
memorizeMinHeight();
389+
if (memorizeMinHeight) {
390+
setMinHeight(containerRef.current?.getBoundingClientRect().height ?? 0);
391+
}
390392

391393
const styles = [];
392394
for (const [property, value] of styleMap) {

0 commit comments

Comments
 (0)