From 4ce1420bbb877627cb64791e576d2b0fb2ff6004 Mon Sep 17 00:00:00 2001 From: Reony Tonneyck Date: Sun, 11 Apr 2021 14:30:33 -0400 Subject: [PATCH] Refined messaging with context Used updates from https://github.com/megaroeny/Figma-Reset-Text-Layer-Name/pull/2, and cherry-picked them over to code.ts file. Notification and logic improved, with contextual notification wording. Thank you very much! Co-Authored-By: Yury Zeliankouski --- code.js | 32 +++++++++++++++----------------- code.ts | 27 ++++++++++++++++++--------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/code.js b/code.js index fd3cbfc..5f30a15 100644 --- a/code.js +++ b/code.js @@ -1,22 +1,20 @@ -let successCount = 0, - layerCount = figma.currentPage.selection.length; - +let successCount = 0, layerCount = figma.currentPage.selection.length; if (layerCount === 0) { - figma.closePlugin("Select at least one Text Layer") + figma.closePlugin("Select at least one Text Layer"); } - figma.currentPage.selection.forEach(node => { - if (node.type === "TEXT") { - node.name = ""; - successCount++ - } - else { - figma.notify('For "' + node.name + '" the name is not reset. Select the Text Layer.') - } -}) - -if (layerCount >= 1 && successCount >= 1) { - figma.notify(successCount + " Text Layer names reset ✅", { timeout: 2000 }) + if (node.type === "TEXT") { + node.name = ""; + successCount++; + } + else { + figma.notify('⚠️ "' + node.name + '" name was not reset. A text layer must be selected.', { timeout: 4000 }); + } +}); +if (layerCount > 1 && successCount > 1) { + figma.notify("✅ " + successCount + " text layer names reset", { timeout: 2000 }); +} +else if (layerCount == 1 && successCount == 1) { + figma.notify("✅ Text layer name reset", { timeout: 2000 }); } - figma.closePlugin(); diff --git a/code.ts b/code.ts index 0d35345..df429ae 100644 --- a/code.ts +++ b/code.ts @@ -1,14 +1,23 @@ -let layerCount = (figma.currentPage.selection.length) - +let successCount = 0, + layerCount = figma.currentPage.selection.length; +if (layerCount === 0) { + figma.closePlugin("Select at least one Text Layer") +} figma.currentPage.selection.forEach(node => { - if (node.type == 'TEXT') { + if (node.type === "TEXT") { node.name = ""; - figma.closePlugin(layerCount + " Text layer names reset ✅"); - return + successCount++ } - else { - figma.notify("That's not a Text layer silly!", { timeout: 2000 }); - figma.closePlugin(); + figma.notify('⚠️ "' + node.name + '" name was not reset. A text layer must be selected.', + { timeout: 4000 }) } -}) \ No newline at end of file +}) +if (layerCount > 1 && successCount > 1) { + figma.notify("✅ " + successCount + " text layer names reset", { timeout: 2000 }) +} +else if (layerCount == 1 && successCount == 1) { + figma.notify("✅ Text layer name reset", { timeout: 2000 }) +} + +figma.closePlugin(); \ No newline at end of file