Skip to content

Commit b5856f4

Browse files
committed
Add selection validation for direct commands in Core.js
Introduced a helper function to validate user selection before executing direct commands. This enhancement ensures that users are notified to select layers if none are currently selected, improving user experience and preventing unnecessary command execution.
1 parent 5936cc7 commit b5856f4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/Core.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,24 @@ function hashLicenseKey(key) {
3737
}
3838
}
3939

40+
// Helper function to validate selection for direct commands
41+
function validateSelectionForCommand(commandName) {
42+
const selection = figma.currentPage.selection
43+
if (selection.length === 0) {
44+
figma.notify('Select some layers first to start using Super Tidy.')
45+
figma.closePlugin()
46+
return false
47+
}
48+
return true
49+
}
50+
4051
// Helper function to handle gating for direct menu commands
4152
function ensureDirectCommandGate(commandName, executeCommand, preferences, UUID, license) {
53+
// First validate selection - skip everything if no selection
54+
if (!validateSelectionForCommand(commandName)) {
55+
return // Exit early, user already notified
56+
}
57+
4258
if (shouldShowCountdown()) {
4359
// Show UI with countdown for unlicensed users
4460
figma.showUI(__html__, { width: 360, height: UI_HEIGHT })

0 commit comments

Comments
 (0)