logseq icon indicating copy to clipboard operation
logseq copied to clipboard

Moving cursor outside of double square brackets doesn't exit the action menu, and causes erroneous text to be entered

Open phoenixeliot opened this issue 4 years ago • 4 comments

What happened?

When typing [[]] links or (()) refs, if you move the cursor outside of the square brackets/parentheses, it leaves the action menu/page search prompt open, resulting in unwanted behavior if you do anything other than exit editing and re-enter edit mode.

Note: This issue is less bad on v0.6.3 (the current version on logseq.com), though it still has part of the problem. So this issue is half regression, half bug that was always there.

Reproduce the Bug

  1. Edit a block
  2. Type some words to be able to move the cursor to later
  3. Move to the middle of the text you typed and type [[; wait for page search action menu to open
  4. Press right arrow until the cursor is outside of the ]] to the right by any number of characters Result: The action menu stays open
  5. Type some text
  6. Press Enter
  7. Move cursor back to the [[]] and type some more text into it
  8. Move cursor to the right of the ]] and type some text
  9. Press Enter Result: It may eat some of the text that you typed outside of the link before

Expected Behavior

When the cursor leaves the [[]], the search prompt should be closed.

On logseq.com (which runs v0.6.3 currently), it almost does this correctly, but it only exits the action menu once you've typed a space; typing text immediately after a ]] that you just edited again still inserts text and an extra ]], same as in this issue.

Screenshots

The current behavior in v0.7.9:

https://user-images.githubusercontent.com/491376/182867712-14e9eb33-2a98-4778-9252-5463505cb85a.mp4

The old, partially better behavior in v0.6.3

https://user-images.githubusercontent.com/491376/182868353-fc97cf6c-876e-4e69-ad38-e66889ba9988.mp4

:

Desktop Platform Information

MacOS 12.4, App, v0.7.9

Mobile Platform Information

No response

Additional Context

I'm already working on a code fix for this.

phoenixeliot avatar Aug 04 '22 14:08 phoenixeliot

Sounds like a regression bug. Should build some E2E test cases on this.

cnrpman avatar Aug 04 '22 14:08 cnrpman

Yeah, I have some tests written already, will get it up when I get to it in my series of PRs today.

My first suspect is that these lines almost never run, as they're the last "else" here, and that this should be moved out of the cond chain: https://github.com/logseq/logseq/blob/7eef27c020a750e42cee55bf6debabd0b6fe417a/src/main/frontend/handler/editor.cljs#L2923-L2925

phoenixeliot avatar Aug 04 '22 20:08 phoenixeliot

I'm not entirely sure why that code should only run if @search-timeout is nil, though. Seems like it'd be fine to run any time the user causes a keyup. I don't feel confident enough to remove that condition yet though.

I guess perhaps because it checks get-search-q to see if we're currently searching, and that will only have a value after the timeout clears..?

phoenixeliot avatar Aug 04 '22 20:08 phoenixeliot

A quick note in case I don't just figure it out and fix it myself imminently: A utility function defined as part of this, text/wrapped-by?, gives a false positive for [[]] with the cursor after the first [.

phoenixeliot avatar Aug 04 '22 21:08 phoenixeliot