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 TextBlock wrong caret position #14627

Merged
merged 1 commit into from Feb 19, 2024
Merged

Conversation

Donzasto
Copy link
Contributor

@Donzasto Donzasto commented Feb 16, 2024

What does the pull request do?

Corrects caret behavior after inserting, losing window focus (detected during debugging) , or programmatically changing a TextBox.

What is the current behavior?

After selecting text from right to left and inserting the same number of characters in the same place or losing window focus, the caret position is displayed before the last (left) character selected. At the same time, after starting to enter new text, it is entered after the first(right) character.
The actual caret position and its display are not the same.

What is the updated/expected behavior with this PR?

The actual caret position and display now remain the same after pasting, losing window focus, or changing programmatically.

How was the solution implemented (if it's not obvious)?

Inserting text of the same length does not trigger OnPropertyChanged for CaretIndex.
After insertion, only SelectionEnd in TextBox.cs fires and no one updates CharacterHit _lastCharacterHit in TextPresenter.cs. Same reason for changing the text field programmatically.
TextPresenter.Render(DrawingContext) uses the old index from CharacterHit _lastCharacterHit for rendering.
Added MoveCaretToTextPosition call when changing SelectionEndProperty in TextBox.cs.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #13648
Fixes #13886
Fixes #14563

Future

In general, after losing the window's focus and returning it, the selected text should remain and not show the caret, as is implemented everywhere (I don't know MacOS).

@Donzasto
Copy link
Contributor Author

@dotnet-policy-service agree

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0045023-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Feb 19, 2024
@maxkatz6 maxkatz6 added the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Feb 19, 2024
Merged via the queue into AvaloniaUI:master with commit cde90cc Feb 19, 2024
6 checks passed
@maxkatz6 maxkatz6 added backported-11.0.x and removed backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch labels Feb 20, 2024
maxkatz6 pushed a commit that referenced this pull request Feb 20, 2024
Gillibald added a commit that referenced this pull request Mar 13, 2024
MrJul pushed a commit that referenced this pull request Mar 13, 2024
maxkatz6 pushed a commit that referenced this pull request Apr 6, 2024
maxkatz6 pushed a commit that referenced this pull request Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants