Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10391 - incorrect cursor position after autocomplete #10647

Merged
merged 4 commits into from
Jul 23, 2021

Conversation

dmonad
Copy link
Member

@dmonad dmonad commented Jul 19, 2021

References

This PR fixes the issue described in #10391.

Code changes

The auto-complete plugin now explicitly sets the cursor position after the replacement.

Previously, we relied on the behavior of modeldb to adapt the cursor position correctly. The autocomplete plugin simply replaced text and the local position would be automatically updated to the position after the replacement. This is no longer possible in all cases because y-codemirror now updates the cursor positions after each change with an algorithm that is designed to work nicely with remote changes. We instead update the position to the position before the replacement, because that will lead to fewer conflicts when multiple peers insert content at the same time.

User-facing changes

None

Backwards-incompatible changes

None

@jupyterlab-dev-mode
Copy link

Thanks for making a pull request to JupyterLab!

To try out this branch on binder, follow this link: Binder

@blink1073 blink1073 added the bug label Jul 19, 2021
@blink1073 blink1073 added this to the 3.1 milestone Jul 19, 2021
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dmonad
Copy link
Member Author

dmonad commented Jul 19, 2021

Thanks for the quick review! I fixed the tests, hope they run now.

@krassowski
Copy link
Member

krassowski commented Jul 19, 2021

I don't think the fix works now. The dict.<tab> example gives me dict.|clear again. What was the sequence the tests were failing on?

Edit: give me a minute to confirm, maybe I had stale binder 👀

@krassowski
Copy link
Member

Yup, not working after the changes that fixed the test:

not-working

Debug info:

patch = {start: 5, end: 5, value: "clear"};
cursorBeforeChange = 5

this means that the condition of cursorBeforeChange < end && cursorBeforeChange >= start will not be true and the fix will not be applied. In fact I, wonder if this condition will ever be true (that would require that cursor is simultaneously before end and after start which should never be true for well behaved patches?) - did you mean to make the condition the other way round? It would help if you add a comment on why this was needed.

Also, maybe it would be useful to add a test for dict.|<tab> -> dict.clear|?

@dmonad
Copy link
Member Author

dmonad commented Jul 21, 2021

Thanks @krassowski for trying out the patch! I fixed the issue on by including the end as part of the range. I also added a test for autocompletion on an empty work (replace "" with "foobar" for example, which should cover the cases described in the original issue).

that would require that cursor is simultaneously before end and after start which should never be true for well behaved patches?

When performing autocomplete on the empty word (e.g. "" ⇒ "dict"), the cursor is within the replaced range. Although in this case start == end. Usually, the cursor would be after the replaced range (e.g. "di|" ⇒ "dict|").

This PR only fixes an edge case. When the cursor is within the replaced word (or directly after it), we expect that the cursor is after the replaced word after the change is performed. All other cases are handled by the existing cursor mapping approach.

@dmonad
Copy link
Member Author

dmonad commented Jul 21, 2021

I rebased because the tests were failing. Now different tests that are unrelated to this PR are failing. I'm going to try rebasing again tomorrow.

Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
@blink1073 blink1073 merged commit 6631799 into jupyterlab:master Jul 23, 2021
@blink1073
Copy link
Contributor

@meeseeksdev please backport to 3.1.x

meeseeksmachine pushed a commit to meeseeksmachine/jupyterlab that referenced this pull request Jul 23, 2021
blink1073 pushed a commit that referenced this pull request Jul 23, 2021
…complete (#10689)

Co-authored-by: Kevin Jahns <kevin.jahns@protonmail.com>
@github-actions github-actions bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Jan 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug pkg:completer status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants