Skip to main content

Code and code block creation with the ` character

Completed

Comments

10 comments

  • Brett

    Typing the first backtick should pair it, but immediately typing a second backtick should "type over" the auto-inserted one, then adding a backtick next to a completed pair should skip the autopairing. So you've hit backtick 3 times and gotten three backticks. I'm not sure what you're experiencing, you may need to provide a screencast.

    0
  • juha.ranta

    I don't have any screencast software or experience right at hand, though I'll look for one if needed. I don't know if this behaviour could be related to that I use the Finnish MacOS, but it's definitely not working properly here. 

    Typing one backtick creates two backticks with the cursor in middle, as would be expected: ``

    If after this I write anything, it becomes four backticks in front of whatever I write: ````for (i in 1)

    Two backticks becomes five backticks: ``````

    If I type backtick three times it becomes ten backticks with the cursor in the end: ``````````

    If I type a backtick, write something to it and finish with backtick it becomes: ````for in in range(1, 10)````

    0
  • Brett

    Ok, that’s definitely odd (and incorrect) behavior. I’ll talk with Fletcher and let you know what else we need to be able to replicate and debug it.

    0
  • juha.ranta

    Thanks Brett. The odd behaviour with tab indent/outdent of which I made other post might also be something that happens for some reason in my setup but not for others?

    0
  • Fletcher Penney

    (I don't speak Finnish so apologies for incorrect terminology...  But the general concepts are correct.)

    The Finnish keyboard I get using the macOS Keyboard Viewer (Keyboard Preferences -> Input Sources -> Show Input menu in menu bar) shows the "`" key to the left of the delete key (when holding down the shift modifier).

    But it's not actually the "`" key, it's a diacritic key for creating things like "è".  When pressing it, the "`" appears, but it is yellow "marked text" and not a true apostrophe character.

    If I use Shift-Opt-`, then it becomes the actual apostrophe key:

    1) The orange coloring goes away in the Keyboard Viewer, meaning it's a "real" key and not a "partial" key (e.g. diacritics and the like).

    2) Things work properly in nvUltra because we are now actually sending ASCII apostrophe characters and not trying to indicate a diacritic

    3) The yellow marked text indicator in the text editor does *not* appear while typing, since we are not sending diacritics

    (You should be able to validate this yourself.)

    So, what to do? After some experimentation, it seems that I can tell when a key stroke is coming in as a diacritic. Which means that it will not be treated as an apostrophe for smart pairs now.

    *But*, if you type something besides a vowel (or any character that can accept the diacritic), then macOS "breaks" the diacritic and it falls back to a similar regular character -- in this case the accent becomes an apostrophe. Additionally, it also seems that macOS does some strange duplication of the keystroke. I would need to dig into further, but it's almost like it resends the original diacritic as an apostrophe, *and* the new apostrophe/diacritic. This is why you were getting extra duplications of the apostrophe character. To work around this, I can disable smart functionality when marked text is present. I *think* this will be ok, but it might also break something else. We'll have to see what happens.

    It seems that the *proper* solution would be:

    1. You can remove "`" from the smart pair characters and then you won't have to worry about this, and you simply have to manually type both apostrophes when you want to indicate a codespan.

    2.  You can use the "proper" keystroke to send a real apostrophe instead of a diacritic (in my tests this seems to be Shift-Opt-`)


    I'm willing to experiment with the workaround approaches above (one is pretty straightforward and should be ok, and the other is probably ok).  But if for some reason it becomes troublesome, then the official answer might be to choose one of these last two options.

    (I guess you could also use some sort of a tool to remap your keyboard to always send an actual apostrophe, but I would bet that would cause you lots of headaches when typing text and I would not recommend it.)

    1
  • Fletcher Penney

    PS>  Unless you have marked text at the time that you tab, this is *probably* not related to any indent/outdent issues.

    0
  • juha.ranta
    OK, I'll try the shift-opt-` when back on my Mac. The way I've been creating backticks is with the shift+` followed by a space which gives the actual ` character ("accented space" becomes `). It usually works with other editors.

    Right now I'm on a Finnish Windows keyboard which is similar to the Mac at least regarding this key, and it seems I can't get the ` character directly with any combination of modifier keys, but shift+` followed by space works like on Mac.
    0
  • juha.ranta

    OK, I tried it on MacOS with the Finnish keyboard. On the Mac shift+alt+` actually does create the character ` directly, which also works in nvUltra. I personally can live with this instead of shift+` followed by space - in fact it's probably more convenient way to create the character once it's in the muscle memory (except you need two hands..). And there's also some behaviour on MacOS (over Windows) that may make it a bit more cumbersome in some situations.

    Just for record in MacOS this Scandinavian "dead key" setup, most other applications (such as Apple Notes or Bear) work something like this:

    - Single press on the shift+` shows the ` character with a yellow background, maybe indicating the character may change with the next key.

    - Pressing the shift+` three times creates ```, with the yellow background moving. You don't need to press space between to have it work. So it's a bit easier to create the characters this way than with the extra alt modifier.

    - Now that I look at my own typing from an outside kind of view, I think I've habitually probably used just three shift+` to create things like code blocks. When writing a `statement` I'm not actually sure if I've usually done shift+` with the following space or without it, perhaps it's been a mixture of those. :)

    So in summary, it's possible to work with shift+alt+` and it may in some sense be more convenient. Many Scandinavians have learned the shift+` followed by space method, and it seems to be the only way to do it on Windows; MacOS has this other shortcut and maybe some additional helpers. However in nvUltra it works faulty and in a different way from most other applications when using the other methods.

    BTW, this kind of diacritical marks or "accents" (such as è) are never used in Finnish or Swedish, nor I think Danish or Norwegian either. We have our own keys for ä, ö, å, etc. Someone's just designed our keyboards that way I guess. In fact I think I've never really used this dead key accentuation feature in my life, but I constantly need the backticks for Markdown. 

    0
  • Fletcher Penney

    (Note:  My comments are specifically about macOS.  Windows rarely does anything "right", so I don't spend a lot of mental energy trying to dig into the details of it.  I use it at work when I have to, and try to avoid it otherwise.  ;)

     

    Yeah -- the shift-` then space is a "lazy" shortcut.  It works (except when it doesn't), but if you're a purist it is abusing a diacritic character.  I'm not saying it shouldn't be used (as clearly it is commonly used), but it does help to understand why it works so that it becomes clearer why it breaks.

     

    Once you "learn" the shift-alt-` it may become easier for you (I find that sometimes I like to do things the right way, even if it takes an extra keystroke), but some people don't care.

     

    It is interesting that the ` key is a dead key by default if you don't actually use it that way....  Maybe remapping it would be worth your time then.

     

    In either case, as I mentioned above, nvUltra's behavior has been changed to be more tolerant of the "wrong but common" approach of converting the "hanging diacritic" into an apostrophe/backtick.  *Unless* that breaks other things, I intend to leave that fix in place.

    0

Please sign in to leave a comment.

Powered by Zendesk