Skip to content

Commit d5edc48

Browse files
authored
fix: When deleting property during search in advanced panel - remove it from results (#4950)
## Description 1. What is this PR about (link the issue and add a short description) ## 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 02bcc55 commit d5edc48

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export const CssEditor = ({
340340
},
341341
}));
342342

343-
const advancedProperties = Array.from(styleMap.keys()) as Array<CssProperty>;
343+
const advancedProperties = Array.from(styleMap.keys());
344344

345345
const currentProperties =
346346
searchProperties ??
@@ -394,7 +394,7 @@ export const CssEditor = ({
394394
keys: ["property", "value"],
395395
}).map(({ property }) => property);
396396

397-
setSearchProperties(matched as CssProperty[]);
397+
setSearchProperties(matched);
398398
};
399399

400400
const afterChangingStyles = () => {
@@ -407,6 +407,25 @@ export const CssEditor = ({
407407
});
408408
};
409409

410+
const handleDeleteProperty: DeleteProperty = (property, options = {}) => {
411+
onDeleteProperty(property, options);
412+
if (options.isEphemeral === true) {
413+
return;
414+
}
415+
setSearchProperties(
416+
searchProperties?.filter((searchProperty) => searchProperty !== property)
417+
);
418+
};
419+
420+
const handleDeleteAllDeclarations = (styleMap: CssStyleMap) => {
421+
setSearchProperties(
422+
searchProperties?.filter(
423+
(searchProperty) => styleMap.has(searchProperty) === false
424+
)
425+
);
426+
onDeleteAllDeclarations(styleMap);
427+
};
428+
410429
return (
411430
<>
412431
{showSearch && (
@@ -420,8 +439,8 @@ export const CssEditor = ({
420439
)}
421440
<CssEditorContextMenu
422441
onPaste={handleInsertStyles}
423-
onDeleteProperty={onDeleteProperty}
424-
onDeleteAllDeclarations={onDeleteAllDeclarations}
442+
onDeleteProperty={handleDeleteProperty}
443+
onDeleteAllDeclarations={handleDeleteAllDeclarations}
425444
styleMap={styleMap}
426445
properties={
427446
searchProperties ?? [...recentProperties, ...currentProperties]
@@ -446,7 +465,7 @@ export const CssEditor = ({
446465
}
447466
}}
448467
onReset={afterChangingStyles}
449-
onDeleteProperty={onDeleteProperty}
468+
onDeleteProperty={handleDeleteProperty}
450469
onSetProperty={onSetProperty}
451470
/>
452471
);
@@ -493,7 +512,7 @@ export const CssEditor = ({
493512
<LazyRender key={property}>
494513
<AdvancedDeclarationLonghand
495514
property={property}
496-
onDeleteProperty={onDeleteProperty}
515+
onDeleteProperty={handleDeleteProperty}
497516
onSetProperty={onSetProperty}
498517
/>
499518
</LazyRender>

0 commit comments

Comments
 (0)