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
[WPF] RichTextArea Selection not working correctly #1234
Comments
On Windows, the line ending characters are somehow not counted to the indices for selections. I currently use the following code as work-around: private void Write(string message, Color c)
{
Append(message + Environment.NewLine, true);
int idx = -1, last = -1;
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
idx = Text.LastIndexOf(message);
last = Text.Length;
}
else
{
var lines = string.Join("", Text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
idx = lines.LastIndexOf(message);
last = lines.Length;
}
if (idx == -1)
return;
Selection = new Range<int>(idx, idx + message.Length);
SelectionForeground = c;
Selection = new Range<int>(last, last);
} But this is definitely a bug... |
Yeah I've used the same hack as @ManuelHu before, it isn't pretty. I'm not sure yet how to effectively address this without being dog slow with large text. Thanks for reporting the issue! |
Hey @DanWBR, This should be fixed in latest develop branch. Could you give it a go? On all platforms newlines are now treated as a single |
Hi @cwensley, there's still one character left to fix: |
Hey @DanWBR, do you have a repro for the off by one issue? I can't seem to reproduce it. |
Maybe I'm using wrong indexes? It does work on macOS and GTK, though. |
@DanWBR, ah yes that won't work the way you have it unfortunately - WPF adds a newline at the end of the What I'd recommend is to keep the current position in a variable and increment it after appending text. Accessing the |
Expected Behavior
Text correctly selected according to defined range.
Actual Behavior
There is a misplacement of 5 characters to the right.
Steps to Reproduce the Problem
Code that Demonstrates the Problem
Specifications
WPF:
GTK2 (Linux):
Xamarin.Mac:
The text was updated successfully, but these errors were encountered: