logseq icon indicating copy to clipboard operation
logseq copied to clipboard

Backquote auto-close behavior: doesn't skip over closing quote, unlike parens/brackets/braces

Open garyo opened this issue 3 years ago • 4 comments

What happened?

Logseq auto-closes parens, brackets and braces, which is nice. Typing the left one auto-adds the right one, leaves the cursor between them. Then later when the user types the right one, it skips over it if it's already at the cursor. Backquotes (for code) are almost the same, except for one annoying difference: when the user types the closing (second) one, logseq always adds another pair even if the "closing" backquote is already at the cursor location. This means the user has to remember to move the cursor right rather than typing the closing backquote.

I recommend skipping over the backquote the same way it skips over closing parens, brackets, and braces.

Reproduce the Bug

In a fresh block, type { and then }. Notice it creates a matched pair of braces with the cursor at the end. This is the desired/expected behavior. In a fresh block, type backquote "`" then another backquote. Notice that it creates four backquotes, with the cursor in the middle of them. This is unlikely to be what the user intends.

Expected Behavior

Backquotes should behave like parens, brackets, and braces. I know it's slightly different because the close char is the same as the open char in that one case, but hopefully the implementation can account for that.

Screenshots

No response

Desktop Platform Information

Win 11, desktop app, 0.6.2

Mobile Platform Information

No response

Additional Context

No response

garyo avatar Mar 09 '22 15:03 garyo

I'm no expert, but I wonder if this code is responsible for the difference? It seems to deliberately exclude backquote from the auto-close behavior:

https://github.com/logseq/logseq/blob/d8bc074be17d3e4c1b780f9ce08e15f2f45193a6/src/main/frontend/handler/editor.cljs#L2877-L2884

garyo avatar Mar 09 '22 16:03 garyo

One thought: maybe this is like this to make it easier to type the triple-backquote syntax for multiline code blocks? If so, the logic could just get slightly smarter: only create a new autopair for backquote if previous two chars are not both backquote. So typing one gets you two (`|`), typing two keeps two (` `|), then typing the third with no intervening chars leaves you with three and cursor at the end (```|).

garyo avatar Mar 09 '22 16:03 garyo

Confirming this behavior still exists. Any idea if there is an acknowledgement of whether or not it is a bug or intended behavior?

corpetty avatar Jun 07 '22 12:06 corpetty

I think someone should be looking into this issue, because I'm using quote a lot, but this behavior really annoy me in which I have to move my hand to shift one character before I can continue typing (Which disrupting my workflow a lot0)

tin-nt avatar Aug 03 '22 13:08 tin-nt

Duplicate of #4380

KaelWD avatar Aug 18 '22 11:08 KaelWD

@garyo I believe I've fixed this issue in #6496. I don't know how the Logseq release process works but hopefully this fix will go out soon.

vmoros avatar Aug 27 '22 15:08 vmoros

It's in the latest nightly, and working great for me! Thank you!

garyo avatar Aug 28 '22 13:08 garyo