Skip to content

Commit

Permalink
feat(rename-layers): final review - undo group
Browse files Browse the repository at this point in the history
  • Loading branch information
mavalroot committed Sep 17, 2024
1 parent b77bc8a commit b1e1296
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/rename-layers-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ penpot.on('themechange', (theme) => {
penpot.ui.sendMessage({ type: 'theme', content: theme });
});

penpot.on('selectionchange', () => {
penpot.on('shapechange', () => {
resetSelection();
});

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);
Expand All @@ -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) =>
Expand All @@ -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();
}
});
Expand Down

0 comments on commit b1e1296

Please sign in to comment.