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

ui.editor cursor jumps to start of text intermittently #2611

Closed
Gilser opened this issue Feb 24, 2024 · 6 comments · Fixed by #2756
Closed

ui.editor cursor jumps to start of text intermittently #2611

Gilser opened this issue Feb 24, 2024 · 6 comments · Fixed by #2756
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Gilser
Copy link

Gilser commented Feb 24, 2024

Description

This is able to be replicated from the nicegui documentation pages in addition to in test applications.

To cause the issue, clear out any existing text in the ui.editor input control, then rapidly start typing characters into it. Especially when there are relatively few characters in the field, the cursor will jump to the beginning of the input which then causes text being typed to start going in before anything else inputted.

Can happen a few times as text is being inputted but it seems to stop after some number of characters are already in the field. Fairly easy to trigger by clearing out all text before quickly inputting more.

Does seem to only be triggered when quickly entering information - by slowly inputting text I've been unable to replicate so far.

@rodja rodja added the bug Something isn't working label Feb 25, 2024
@falkoschindler
Copy link
Contributor

falkoschindler commented Feb 26, 2024

Oh wow, thanks for reporting this issue, @Gilser! This UX feels really bad. 😕

I thought we might just need to add LOOPBACK = False to the ui.editor class (like we do for ui.input or ui.number), but it leads to a similar behavior: Whenever the cursor is at the end, typing a character lets it jump back to the start. Otherwise it behaves nicely.

We'll need to further investigate the problem.

@falkoschindler falkoschindler added the help wanted Extra attention is needed label Feb 26, 2024
@intrinsically
Copy link

i've been using nicegui to build some intranet apps. i don't get the cursor jumping problem when i'm deploying locally, but when i deploy on AWS behind a VPN then it's really really bad - cursor jumping every 5 characters or so even if i have existing text.

could it be latency related?

@intrinsically
Copy link

as a further bit of info: i can reproduce the problem quite easily in the controls demo here: https://nicegui.io/documentation/editor

@falkoschindler
Copy link
Contributor

Thanks, @intrinsically!

I think I found a lead: When setting LOOPBACK = False and removing the following lines, the bug is gone.

if (element.props["loopback"] === False && event.type == "update:modelValue") {
element.props["model-value"] = args;
}

Let me try to explain what I think is happening:

  1. Usually value elements like ui.switch need to send an update:modelValue event to the server, which updates its model and sends the new value back to the front end. This is what we call "loopback".
  2. For elements that can change rapidly like ui.input or ui.number, we disable this loopback procedure and set the new value directly on the client (see the code snippet above).
  3. But there seems to be a third group of elements like ui.editor that shouldn't use loopback to prevent the cursor from jumping around, but also shouldn't set the model value programmatically on the client, because it also messes with the cursor position.

So I think we either need to change LOOPBACK from a boolean flag to something like a Literal string to distinguish these three types of value updates, or we add a second flag to define whether the new value should be set directly on the client or not.

@falkoschindler falkoschindler self-assigned this Mar 23, 2024
@falkoschindler falkoschindler added this to the 1.4.20 milestone Mar 23, 2024
@falkoschindler falkoschindler removed the help wanted Extra attention is needed label Mar 23, 2024
@falkoschindler falkoschindler linked a pull request Mar 23, 2024 that will close this issue
@intrinsically
Copy link

intrinsically commented Mar 27, 2024

ah great stuff falko, interesting to get a bit of info on how the underlying interaction model works. what's a good way for me to set up my environment to start debugging this stuff myself? i guess i'll just check out the project and see if i can build/run it. i'm interested in debugging why some components (like the markdown viewer) don't seem to be rendered (or capable of holding a value) in a tab until the user clicks on the tab.

p.s. not sure if you are interested, but i program using nicegui using classes rather than functions, have developed a few techniques that might be useful if you are interested. took a few tried to get it right. i couldn't find any class-based examples in the examples directory...

@intrinsically
Copy link

what's a good way for me to set up my environment to start debugging this stuff myself?

umm wow, i just cloned it, started up venv and pycharm and it worked immediately. good stuff... possibly the easiest environment i've ever had to set up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants