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.