Reselect Sketch Plugin
Quickly restore previous selections or save them for use later.
Ever deselect when you didn’t mean to? Wish you could save a tricky selection that you’re doing over and over? Download the Reselect plugin.
Note: This uses some new developer features found only in Sketch 3.8. Make sure you’re up-to-date before using this plugin.
Want to restore a selection you mistakenly deselected?
That’s it! By default you can restore 5 selections. To change that, check out the Settings section below.
Want to save a selection for use later?
You can save as many selections as you want. They’ll persist even after you close the document.
Want to load a previously saved selection?
A dropdown list with all of your previously saved selections in the current document will pop up. Done!
Want to update the settings?
You can change the max number of selections that can be restored and whether to auto check for updates. Make sure not to set the max number of selections too high — it could affect performance.
Let me know if this plugin saves time in your design process. Hit me up on Twitter with any feedback or suggestions.
Or, how Reselect works
Restoring a Selection — The latest Sketch release (3.8), includes support for Actions. This basically allows you to listen for an event. In the case of Reselect’s Restore functionality, we are capturing the SelectionChanged action and then grabbing the oldSelection.
Next, we grab the objectID of each layer and store it in the mainThread. When the user restores a selection, we just grab that group of selected layers off the top of the group of previous selections and that’s it.
Saving a Selection — Not much magic here. We grab the currently selected layers and pull out their objectID’s. Next, we capture the selection name the user provided and store all of that in a JSON file with the document’s objectID as the file name.
Loading a Selection — I bet you’ve figured it out by now. We grab the file name that matches the user’s current document objectID, pull out all of the saved selections and then display them in a dropdown to the user.
Head over to the GitHub page if you want to see everything work. I commented the code as much as possible to explain what was going on.