Repository navigation
Conversation
Member
|
I cherry-picked your changes into my WpfRuntime repo, the GitHub Actions CI build passed and produced a NuGet package. You can now install the following package in your project to test out / use your fix: <PackageReference Include="WpfLab.WpfRuntime" Version="1.1.0.1-test.20261123132506.55ca5e" />See: WpfLab/WpfRuntime#46 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3630
/cc @pranav-gupta-msft @amarinov-msft
Description
The issue is that some edits require changes to the document structure. In #3630, such edit is inserting text in front of the first
BlockUIContainer, which needs to insert a Paragraph there to hold the text. When the edit comes from an IME, we are under lock in which we are not allowed to announce changes to the document. IME has two ways to request edit:InsertTextAtSelectionandSetText. The former API has a structure allowing us to communicate back to the IME the changes we had to do.SetTextdoes not. The current behavior then is we do the necessary changes, cannot tell anyone, character offsets get out of sync and we fail fast when we find out. "Characters" here includes special characters representing a start of an element in a document ("left edge").The fix is we hide the newly created elements from the IME (defer their edges) until we are allowed to announce changes, at which point we raise the normal events about document changes. A tree keeps a track of list of elements that have an deferred edge.
All new code reachable from
SetTexthas previously caused crash, no existing behavior should be changed.Now
InsertTextAtSelectionincludes change in behavior that is strictly not required to fix the crash. When the fix is taken, non-IME typing andSetTextbehave the same - when you type over a selection, the selection is replaced as expected. That is not currently the case withInsertTextAtSelectionwhich collapses the selection first (or in same cases rejects the edit). That seems wrong, so I aligned the behavior with the other two methods, but again all unaffected scenarios should go through existing code path.Finally, when user types something through IME and we have to create a Paragraph for it, cancelling the composition does not remove the inserted Paragraph. This is similar to typing without IME where backspace also does not remove the inserted Paragraph. It is possible to keep track of the implicit Paragraph and automatically remove it when composition is cancelled, but it was too much extra code for minimal benefit.
This is one of the more complex parts of WPF and I am not married to the solution. If anyone has better suggestions how to address this (I tried several), chime in.
Customer Impact
Without this fix, customer applications will crash / fail fast with
ExecutionEngineExceptionwhenever typing using IME when the cursor is at aBlockUIContainerboundary.Regression
No. Repros in .NET Framework.
Testing
Tested few scenarios using Microsoft rule-based TSF (Tamil Anjali) including the case in #3630 which crashes without the fix and does not crash with the fix. I also tested it with voice input, as some code paths do not execute when typing on keyboard (namely if there is a preexisting selection, TSF first calls TestKeyDown, which translates into our OnPreviewKeyDown, where we find out we have a selection, we delete it, tell the IME, which sees it as a conflict and does not start a composition - voice does not send key downs).
Tested using locally built WPF x64 using 12.0.100-alpha.1.26569.103 SDK.
It needs to be said that there is a lot of test cases and it is very likely I missed some. I think typing over pre-selected Tables still causes a crash, and I think IME trying to insert new lines into Hyperlnk will cause crash, but I haven't tested those as that is not related to the reported issue.
Risk
All new and changed code should execute only in a specific case - the caret or selection touches a BlockUIContainer edge. Most of the new code only runs in scenarios where we currently crash. Slight change of behavior when IME types over selection using
InsertTextAtSelectionto align it with other methods of input (and the expectation that typing over a selection replaces it).Microsoft Reviewers: Open in CodeFlow