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

Ignore control characters on text input #296

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danipen
Copy link
Collaborator

@danipen danipen commented Jun 6, 2024

When hitting the Escape key or other control keys, the _selection?.OnTextInput() method is executed, passing the string "\u001B" (ASCII 27 control char) to the HandleTextInput method.

This method matches every row because this comparison always returns true (see this .NET fiddle), causing that the selection is moved 1 row down every time the user hits the Escape key:

string escapeSequence = "\u001B"; // ESC - ASCII char 27
Console.WriteLine("something".ToUpper().StartsWith(escapeSequence));

True

This PR changes filters out control characters on method OnTextInput.

@grokys Question: Should Avalonia filter out these events in OnTextInput when the text contains control characters?

@danipen danipen requested a review from grokys June 6, 2024 09:36
@danipen
Copy link
Collaborator Author

danipen commented Jun 6, 2024

I opened an issue in dotnet/runtime#103116

Instead of filtering the control characters
@danipen
Copy link
Collaborator Author

danipen commented Jun 6, 2024

I changed the implementation to use StringComparison.Ordinal as recommended here.

@danipen
Copy link
Collaborator Author

danipen commented Jun 6, 2024

Revert the latest changes, it's not a good practice to ignore culture, so it's probably a better implementation to filter out control characters at the beginning.

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.

None yet

1 participant