Skip to content

Commit

Permalink
Refined messaging with context
Browse files Browse the repository at this point in the history
Used updates from #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 <[email protected]>
  • Loading branch information
megaroeny and tank666 committed Apr 11, 2021
1 parent 4eb54cd commit 4ce1420
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
32 changes: 15 additions & 17 deletions code.js
Original file line number Diff line number Diff line change
@@ -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) {

This comment has been minimized.

Copy link
@tank666

tank666 Apr 13, 2021

Author Contributor

You can also delete layerCount here. This will remain if (successCount > 1) {…}.

figma.notify("✅ " + successCount + " text layer names reset", { timeout: 2000 });
}
else if (layerCount == 1 && successCount == 1) {

This comment has been minimized.

Copy link
@tank666

tank666 Apr 13, 2021

Author Contributor

Not taken into account if one text and non-text (one or more) layers are selected. At this stage, no successful notification appears.
You need to fix code.js and code.ts to else if (layerCount >= 1 &&….
Better yet, delete layerCount from this line so that it looks like this: else if (successCount == 1) {….

This comment has been minimized.

Copy link
@megaroeny

megaroeny Apr 13, 2021

Author Owner

It works for a non-text layer, and it works for one text layer, which is why I separated conditions for else if for a singular selection. I tested it multiple times on non-text layers, and it gives you the first else message. Did you run the latest published plugin to test it?

This comment has been minimized.

Copy link
@tank666

tank666 Apr 13, 2021

Author Contributor

Yes I run the latest published plugin code. You can check it yourself. Select one (or more) frame and one text layer. You will not see a successful notification.

Your code now works like this:
Line 14. if (layerCount > 1 && successCount > 1) {…}
At least two layers are selected, and at least two must be text layers.

Line 17. else if (layerCount == 1 && successCount == 1) {…}
Only one layer is selected and it is a text layer. If you select, for example, Frame and Text Layer, then there is no successful notification, because this does not match the condition, but it also does not apply to the condition on Line 14. This code does not take into account that n frames and only one text layer can be selected.

My fix:
Line 17. else if (successCount == 1) {…}
It doesn't matter how many frames are selected, but only one layer should be a text layer. There is a successful notification.

This comment has been minimized.

Copy link
@megaroeny

megaroeny Apr 13, 2021

Author Owner

Ohhhh! Wait, are you trying to get the functionality to also work if I accidentally select a frame or other object, with a text layer at the same time? I will try this out later, thanks.

This comment has been minimized.

Copy link
@tank666

tank666 Apr 13, 2021

Author Contributor

This is still code optimization and bug catching :-) But I thought it would be great if the plugin looked for all text layers in selected frames, groups, etc.

This comment has been minimized.

Copy link
@megaroeny

megaroeny Apr 14, 2021

Author Owner

I updated it! I tested it out and I see what you mean. This is great, thank you! I'll publish a new update.

This comment has been minimized.

Copy link
@tank666

tank666 Apr 14, 2021

Author Contributor

But I thought it would be great if the plugin looked for all text layers in selected frames, groups, etc.

Hi @megaroeny! You can look and test, additional functionality that I have made. If frames, groups, etc. are selected, the plugin will search for all text layers in them, and then reset the names of these text layers. That is, there will be no more notification «⚠️ "Frame 120" name was not reset. A text layer must be selected».

Sources:

figma.notify("✅ Text layer name reset", { timeout: 2000 });
}

figma.closePlugin();
27 changes: 18 additions & 9 deletions code.ts
Original file line number Diff line number Diff line change
@@ -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 })
}
})
})
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();

0 comments on commit 4ce1420

Please sign in to comment.