Skip to content

Commit bb861e9

Browse files
committed
Support Undo blocks for penpot
1 parent a2ddfd7 commit bb861e9

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

penpot/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Super Tidy",
3-
"description": "Plugin description",
3+
"description": "Rename, reorder and tidy all your nodes in 1 click",
44
"code": "./dist/core.js",
55
"icon": "./icon.png",
66
"permissions": [

src/Core.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ function ensureDirectCommandGate(commandName, executeCommand, preferences, UUID,
8686

8787
// Bind direct countdown completion handler
8888
MessageBus.bind('direct-countdown-complete', (msg) => {
89+
let historyId = FP.startUndoBlock()
8990
executeCommand()
91+
FP.finishUndoBlock(historyId)
9092
FP.closePlugin()
9193
})
9294
} else {
9395
// Execute immediately if licensed
96+
let historyId = FP.startUndoBlock()
9497
executeCommand()
98+
FP.finishUndoBlock(historyId)
9599
FP.closePlugin()
96100
}
97101
}
@@ -199,10 +203,12 @@ Storage.getMultiple([
199203
var TIDY_ENABLED = msg.options.tidy
200204
var PAGER_ENABLED = msg.options.pager
201205

206+
let historyId = FP.startUndoBlock()
202207
if (TIDY_ENABLED) cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances, preferences.layout_paradigm || 'rows')
203208
if (RENAMING_ENABLED) cmdRename(preferences.rename_strategy, preferences.start_name, preferences.layout_paradigm || 'rows')
204209
if (REORDER_ENABLED) cmdReorder(preferences.layout_paradigm || 'rows')
205210
if (PAGER_ENABLED) cmdPager(preferences.pager_variable, preferences.layout_paradigm || 'rows')
211+
FP.finishUndoBlock(historyId)
206212
FP.showNotification('Super Tidy')
207213
setTimeout(() => FP.closePlugin(), 100)
208214
})

src/utils/FigPen.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,22 @@ export default class FigPen {
207207
}
208208
}
209209

210+
startUndoBlock() {
211+
if (this.designTool === FIGMA) {
212+
console.warn('startUndoBlock not supported in Figma. https://developers.figma.com/docs/plugins/api/properties/figma-commitundo/')
213+
} else if (this.designTool === PENPOT) {
214+
console.log('startUndoBlock', penpot.history)
215+
return penpot.history.undoBlockBegin()
216+
}
217+
}
218+
219+
finishUndoBlock(historyId) {
220+
if (this.designTool === FIGMA) {
221+
console.warn('finishUndoBlock not supported in Figma. https://developers.figma.com/docs/plugins/api/properties/figma-commitundo/')
222+
} else if (this.designTool === PENPOT) {
223+
console.log('finishUndoBlock', penpot.history)
224+
return penpot.history.undoBlockFinish(historyId)
225+
}
226+
}
227+
210228
}

0 commit comments

Comments
 (0)