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] 20 Autocomplete Bug (alternative solution) #155

Conversation

Apollo3zehn
Copy link
Member

During my review of PR #149 ([Fix] 20 Autocomplete Bug) I tried to understand the root cause of the problem and finally found it.

Here is the problem description:

  1. When users types into the autocomplete input for the first time, they are able to do so successfully. E. g. typing 10min works.
  2. But the second time a value is being entered, it usually fails and the value is replaced with 1 s.

The root cause of this behavior is the following:

  1. Initially the autocomplete input shows the value 1 s. When a user types e.g. 10 min there will be internal exceptions thrown for every keystroke until 10 min is entered completely. Whenever an exception is thrown (because partial values like 10 mi are invalid), the return value is new Period(default) which equals to 1 s as shown here:
    ? TimeSpan.FromSeconds(1)
  2. This means that as long as incomplete (= invalid) values are being entered, the autocomplete input value does not change, internally it always has the value of 1 s.
  3. As long as the internal value does not change, the user can continue entering characters until the input value becomes valid
  4. However, when, for instance, the user successfully entered 10 min and then tries to enter 5 s, this immediately fails because - as described above - partial values like 5 are invalid and cause exceptions to be thrown. This in turn leads to a return value of new Period(default) which in turn equals to 1 s, so now the internal value does change and the input is immediately replaced with 1 s and the the user cannot continue entering the 5 s value.

So the obvious solution is to not return default or new Period(default) but the current value instead until the new input is valid. The current value is not directly accessible in the converter but a getCurrentValue function can be passed into the converter's constructor to work around this problem as I did in the first commit.

@Apollo3zehn Apollo3zehn self-assigned this Oct 2, 2024
@Apollo3zehn Apollo3zehn force-pushed the alternative-20-10-min-eintippen-ist-doof-es-wechselt-dann-auf-1-s branch from 7255114 to 0d01aa2 Compare October 2, 2024 20:26
@Apollo3zehn
Copy link
Member Author

I have renamed PeriodConverter.cs to Period.cs which makes it a bit harder to see what has actually changed :-(

@Apollo3zehn Apollo3zehn removed the request for review from Conundraah October 2, 2024 20:31
@Apollo3zehn Apollo3zehn merged commit 0b1ef48 into dev Oct 2, 2024
3 checks passed
@Apollo3zehn Apollo3zehn deleted the alternative-20-10-min-eintippen-ist-doof-es-wechselt-dann-auf-1-s branch October 2, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant