This Week's Sponsor:

Kolide

Ensures that if a device isn’t secure it can’t access your apps.  It’s Device Trust for Okta.


Simulating Multiple Cursors in Editorial

Editorial

Editorial

When I’m writing with Editorial or Byword, I miss the multiple cursors feature of Sublime Text. Seemingly an extra geeky addition with no practical utility, multiple cursors had become part of my editing workflow as they allowed me to select multiple positions in a document and act on them at once. For example, I could select multiple lines and prefix them with an asterisk to turn them into a Markdown list, or select multiple instances of a word and modify them with a single keystroke without using Find/Replace or other hacks. The feature was built into Sublime and it was great. So of course I made a workflow for Editorial.

Because it’s the end of the year and I’m feeling festive and thankful, I’m posting two workflows to simulate multiple cursors in Editorial. The first one allows you to save selections for multiple bits of non-contiguous text at once and, when you’re done, wrap them inside any character(s); it’s useful if you want to make multiple words bold/italic, or if you want to enclose them inside parentheses. The second workflow lets you add inline Markdown links for each selection, fetching a webpage URL from the Editorial browser.

Rather than provide you with static screenshots and a boring written explanation, here’s a video of the workflows in action.

Here’s a few notes on the first workflow:

  • The raw input in the console that repeats itself until you enter “n” (for “No”) is based on the “Set count” action by Ed Gauthier from this workflow. By default, it’ll run for 100 consecutive times until dismissed; you can tweak the number as a “Count” parameter in the custom action. It’s, essentially, a hack to simulate a while loop.
  • The raw input is also a hack in that it’s the only way I’ve found in Editorial to enter user input without bringing up a modal view that would prevent text selection. An alert dialog wouldn’t let me select text in the editor. Alas, raw input can’t be automatically hidden with Python, and Editorial doesn’t come with any other non-modal action for user interaction.
  • Selections are saved as a list of ranges to a variable in a (x, y) format. The workflow removes the parentheses and sorts lines alphabetically, re-saving the “cleaned” ranges to the same variable.
  • The workflow requests text to insert on the left and right, and saves your input to two separate variables.
  • In the last Repeat block, for every selection range text is selected and replaced with the wrapping characters around the original text.
  • The trick to get everything to work is to run the Repeat block with the “Reverse” flag on: this will run multiple text replacements in a row starting from the bottom, which won’t cause issues with re-calculating ranges at the top.

As for the second workflow with inline links:

  • In the last Repeat block, Python selects text, then shows a HUD that asks you to choose a URL for the first selection in the block.
  • A browser variable is paused, allowing you to open the browser and find a URL for each selection. When you’re done, tap the blue button in the pause slider and the variable will be saved, replacing selected text to generate a Markdown link.

As you can see, these workflows are pushing the limits of what’s currently possible in Editorial for text selections, repeat blocks, and non-modal user interaction. Though you can use the first workflow to add whitespace before text (just place the cursor without selecting anything and enter “y”) and you could probably tweak the workflows to be a little more flexible (text replacements instead of wrapping, etc), my solution isn’t obviously a full-fledged alternative to Sublime’s real multiple cursors.

For the future, it’d be great to have true “while” or “until” conditions for repeat blocks in Editorial, as well as more actions for non-modal interaction with custom controls. Or maybe multiple cursors straight on the iPad. Until then, you can download my workflows here and here. Enjoy, and Happy New Year.

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.