From aa7a2a27644b974b06da0f4108c5a30d3c7368e9 Mon Sep 17 00:00:00 2001 From: startewho Date: Thu, 13 Jul 2023 17:11:07 +0800 Subject: [PATCH 1/2] fix 12161 --- src/Avalonia.Controls/Utils/StringUtils.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/Utils/StringUtils.cs b/src/Avalonia.Controls/Utils/StringUtils.cs index 2ea47b442a..b664687650 100644 --- a/src/Avalonia.Controls/Utils/StringUtils.cs +++ b/src/Avalonia.Controls/Utils/StringUtils.cs @@ -76,7 +76,7 @@ namespace Avalonia.Controls.Utils } var codepoint = new Codepoint(text[index]); - + if (!codepoint.IsWhiteSpace) { return false; @@ -85,12 +85,16 @@ namespace Avalonia.Controls.Utils // preceeded by lwsp. if (index > 0) { - var nextCodePoint = new Codepoint(text[index + 1]); - - if (nextCodePoint.IsBreakChar) + if (index + 1 < text.Length) { - return true; + var nextCodePoint = new Codepoint(text[index + 1]); + + if (nextCodePoint.IsBreakChar) + { + return true; + } } + return true; } switch (codepoint.GeneralCategory) @@ -125,7 +129,7 @@ namespace Avalonia.Controls.Utils } cursor = Math.Min(cursor, text.Length); - + int begin; int i; int cr; @@ -181,7 +185,7 @@ namespace Avalonia.Controls.Utils { return cursor; } - + if (cr < text.Length && text[cr] == '\r' && cr + 1 < text.Length && text[cr + 1] == '\n') { lf = cr + 1; @@ -214,9 +218,9 @@ namespace Avalonia.Controls.Utils { return i; } - + var cc = GetCharClass(text[i]); - + // skip over the word, punctuation, or run of whitespace while (i < cr && GetCharClass(text[i]) == cc) { From 4c1d7b4a204e437ac0f1e648361522753d650800 Mon Sep 17 00:00:00 2001 From: startewho Date: Fri, 14 Jul 2023 08:38:00 +0800 Subject: [PATCH 2/2] Update StringUtils.cs --- src/Avalonia.Controls/Utils/StringUtils.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Utils/StringUtils.cs b/src/Avalonia.Controls/Utils/StringUtils.cs index b664687650..0ae1ef0b97 100644 --- a/src/Avalonia.Controls/Utils/StringUtils.cs +++ b/src/Avalonia.Controls/Utils/StringUtils.cs @@ -94,7 +94,11 @@ namespace Avalonia.Controls.Utils return true; } } - return true; + else + { + return true; + } + } switch (codepoint.GeneralCategory)