0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-04 13:50:13 -05:00

feat(rename-layers): final review - undo group

This commit is contained in:
María Valderrama 2024-09-13 11:51:25 +02:00
parent 237ede9ce7
commit 2909bcceb6

View file

@ -9,7 +9,7 @@ penpot.on('themechange', (theme) => {
penpot.ui.sendMessage({ type: 'theme', content: theme });
});
penpot.on('selectionchange', () => {
penpot.on('shapechange', () => {
resetSelection();
});
@ -17,6 +17,8 @@ penpot.ui.onMessage<PluginMessageEvent>((message) => {
if (message.type === 'ready') {
resetSelection();
} else if (message.type === 'replace-text') {
const blockId = penpot.history.undoBlockBegin();
const shapes = getShapes();
const shapesToUpdate = shapes?.filter((shape) => {
return shape.name.includes(message.content.search);
@ -29,9 +31,13 @@ penpot.ui.onMessage<PluginMessageEvent>((message) => {
);
});
updateReplaceTextPreview(message.content.search);
penpot.history.undoBlockFinish(blockId);
} else if (message.type === 'preview-replace-text') {
updateReplaceTextPreview(message.content.search);
} else if (message.type === 'add-text') {
const blockId = penpot.history.undoBlockBegin();
const currentNames = message.content.map((shape) => shape.current);
const shapes = getShapes();
const shapesToUpdate = shapes?.filter((shape) =>
@ -41,6 +47,9 @@ penpot.ui.onMessage<PluginMessageEvent>((message) => {
const newText = message.content.find((it) => it.current === shape.name);
return (shape.name = newText?.new ?? shape.name);
});
penpot.history.undoBlockFinish(blockId);
resetSelection();
}
});