TextBox SelectAll Input Chinese crash
See original GitHub issue- .NET Core Version: .NET6
- Windows version: (
Windows10
) - Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:TextBox SelectAll Input Chinese crash
<Grid>
<TextBox
Name="textEdit"
AcceptsReturn="False"
TextWrapping="NoWrap" />
</Grid>
public MainWindow()
{
InitializeComponent();
//In actual business, sometimes I need to assign a string with a newline character
textEdit.Text = "testasdfasdfgasd阿斯顿发斯蒂芬\r\n撒旦法师打发斯蒂芬\r\n阿斯顿发送到发送到\r\n";
}
When there are multiple lines of strings, when using the Chinese input method to input, the selected text will crash directly I know setting AcceptsReturn=“True” UndoLimit!=“0” will fix this But I need to use Enter event, so it doesn’t work for me So how should I solve this problem?
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
exception thrown from TextChanged event for chinese input
I am observing a crash while entering Text in Chinese language to TextBox with TextChanged event implemented. The text I am entering is...
Read more >130867 – Changing Chinese font size in a text box would fail ...
Select all the characters, click menu "Format - Characters", and change the Asian Text Font size to 14. When clicking OK, Writer crashed....
Read more >Sudden Crashes on Keyboard Input and File Download
In the case of typing, the crash report seems to put the issue inside of the ... When I switch among input methods,...
Read more >WPF DataBinding sets Property twice for Chinese ...
I have the following code C# code: using System.ComponentModel; using System.Windows; namespace WpfApp1 { public partial class MainWindow ...
Read more >TextBox.SelectAll() doesn't work - sometimes - C# / C Sharp
In a TextBox::KeyDown event I check to see if the Enter Key has been pressed, ... but the SelectAll() method appears to not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The documentation for
AcceptsReturn
says:This is clearly wrong either way. First, it assumes that ENTER key will result into a new line in the text, which might not be the case for IME. Second, it also causes pasted text to be trimmed after the first new line, which normally has nothing to do with ENTER key. It does not prevent new lines in the
Text
property though, because you can set it directly. Changing either of these two behaviors would be a breaking change.Filtering during composition update is problematic. First it is rude to mess with the IME by coercing its output in the middle of the composition. If the filtering is desired, it should happen when the composition is finished. Second, the IME is already done by this point, the framework is only replaying the composition events that had happened in the storage, so the IME cannot deal with the coercions even if it wanted to. And finally, it destabilizes the whole replay stack because the recorded text pointers will no longer be valid (you will run into that if you simply remove the assert) and fixing it up would be a lot of work that only the IME might be qualified to do.
I am not a big fan of all this filtering to begin with, but we can’t really remove it at this stage. I think the right thing to do here is to only do the filtering at the end of the composition, i.e. replace line 1981 above with
text = composition.CompositionText
.(Note also that there is
CharacterCasing
property on theTextBox
that is enforced by filtering. This uses the current input language and Unicode does not guarantee that such casing changes will not change the number of characters in the string, so this is a similar bug waiting to happen. Also note that the documentation for this property has a remark “This property does not affect characters that are added programmatically” which would be fitting forAcceptsReturn
property too. And theAcceptsTab
replaces tabs with spaces, which might have been a better design forAcceptsReturn
too.)YES