Using return key to jump over Markdown characters

I’m not sure the best way to describe this, but here I go!

iA Writer has a feature where if you use a shortcut for emphasis - like Command-B for bold, clicking the return button will skip over the markdown charachters and allow you to keep writing withought indenting the charachters. Does anything like this exist in Drafts? Thanks!

Nothing exactly like that, no.

I’m not sure what actions you have for things like bold. The current versions of the default bold/emphasis and similar actions (in the “Markdown” action group) place the cursor after the markup when used, so it should not be necessary to move the cursor to continue typing. If that is not how yours behave, consider installing updated versions from the Directory (current bold action, for example), or reinstalling default action groups from Settings > Maintenance.

Thanks - I am using the current bold action you linked too. I like to indicate emphasis with the shortcut prior to writing the emphasized word. It would be awesome not to have to click the arrow key twice before continuing to write, but maybe that’s not possible. Thanks for all your great work!

But it is! Having to move to the right of Markdown characters would drive me nuts. Or having to move to the right of any other characters, which is why I turned off the auto-matching of brackets etc. and use an action too to insert either the opening or closing bracket.

This simple action does the trick for bold (works both in when you write and when you highlight already existing text):

// Apply Markdown bold to selection, or insert ** if no selection

var sel = editor.getSelectedText();
var selRange = editor.getSelectedRange();

if (!sel || sel.length == 0) {
  editor.setSelectedText("**");
  editor.setSelectedRange(selRange[0]+2,0);
}
else {
  editor.setSelectedText("**"+sel+"**");
  editor.setSelectedRange(selRange[0]+selRange[1]+4,0);
}

Set the keyboard shortcut for it to cmd-b and you should have what you want.

For italics use the same script, just replace the double asterisks by single ones and +2 by +1 and +4 by +2.

Thank you! This is really close to working for me. Selecting a word and using the action is perfect - it surrounds it with the asterisks and moves the cursor after them.

However, when I use the action before typing, it gives me two asterisks and puts the cursor after them. My dream is to have the cursor appear between the asterisks and then advance to after them after I hit return (or maybe some other key combination if return doesn’t work in this case).

No worries if I’m asking too much - thanks!

Ah, I think now I got you.

My approach is toggling, every Markdown markup (like italics) has its own shortcut which switches it on and off. This is my muscle memory’s preferred way to write because I use rich text apps too and that’s how they work. And since I don’t mind if I write in italics or if the text gets italicized only after the closing askterisk I can use the simple script from above that just inserts single or double asterisk instead of inserting 2/4 and placing the cursor in between.

You on the other hand want a pair of Markdown markups, the cursor in between, and a single “escape” keyboard shortcut for all Markdown markups, right?

The question is, which ones? A single asterisk (or underscore), double asterisks, and triple asterisks (for bold-italic)? More? Like brackets (which can be Markdown) too?

An action could check if any characters/glyphs right to the cursor do exist, and if so, check a list containing at least three, two or one asterisks, and if any of the character/glyph sequences are detected right to the cursor move the cursor to the right of the detected sequence.

If you decided to not only go for asterisks but brackets too—should the “escape” action only move to the right of one detected character/glyph sequence or all of them? For example:

[^1 … ( … **Bold text in brackets in a footnote.|**)]

| is the cursor position. Where should the action move it? Right behind the double asterisks: **|? Or right behind the squared bracket: **)]|?

Which ever way, it can be done. But I don’t know how to set that (or any) action to the Return key just with Drafts. Additional tools like Keyboard Maestro or Better Touch Tool could provide it though[1].

But that would make the action more complicated because it would have to identify for every single Return if it is simply meant as Return or as “escape”.


  1. E. g. it totally annoys me that in Messages on the Mac Return sends the message instead of simply starting a new paragraph, and I fixed that with Better Touch Tool. ↩︎