Fixes #4387. Runes should not be used on a cell, but rather should use a single grapheme rendering 1 or 2 columns (#4388)

* Fixes #4382. StringExtensions.GetColumns method should only return the total text width and not the sum of all runes width

* Trying to fix unit test error

* Update StringExtensions.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Resolving merge conflicts

* Prevents Runes throwing if Grapheme is null

* Add unit test to prove that null and empty string doesn't not throws anything.

* Fix unit test failure

* Fix IsValidLocation for wide graphemes

* Add more combining

* Prevent set invalid graphemes

* Fix unit tests

* Grapheme doesn't support invalid code points like lone surrogates

* Fixes more unit tests

* Fix unit test

* Seems all test are fixed now

* Adjust CharMap scenario with graphemes

* Upgrade Wcwidth to version 4.0.0

* Reformat

* Trying fix CheckDefaultState assertion

* Revert "Trying fix CheckDefaultState assertion"

This reverts commit c9b46b796a.

* Forgot to include driver.End in the test

* Reapply "Trying fix CheckDefaultState assertion"

This reverts commit 1060ac9b63.

* Remove ToString

* Fix merge errors

* Change to conditional expression

* Assertion to prove that no exception throws during cell initialization.

* Remove unnecessary assignment

* Remove assignment to end

* Replace string concatenation with 'StringBuilder'.

* Replace more string concatenation with 'StringBuilder'

* Remove redundant call to 'ToString' because Rune cast to a String object.

* Replace foreach loop with Sum linq

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
BDisp
2025-11-20 18:45:13 +00:00
committed by GitHub
parent 726b15dd28
commit cd75a20c60
53 changed files with 2654 additions and 2145 deletions

View File

@@ -198,7 +198,7 @@ internal partial class DriverAssert
IDriver? driver = null
)
{
List<List<Rune>> lines = [];
List<List<string>> lines = [];
var sb = new StringBuilder ();
driver ??= Application.Driver!;
@@ -211,13 +211,13 @@ internal partial class DriverAssert
for (var rowIndex = 0; rowIndex < driver.Rows; rowIndex++)
{
List<Rune> runes = [];
List<string> strings = [];
for (var colIndex = 0; colIndex < driver.Cols; colIndex++)
{
Rune runeAtCurrentLocation = contents! [rowIndex, colIndex].Rune;
string textAtCurrentLocation = contents! [rowIndex, colIndex].Grapheme;
if (runeAtCurrentLocation != _spaceRune)
if (textAtCurrentLocation != _spaceRune.ToString ())
{
if (x == -1)
{
@@ -226,11 +226,11 @@ internal partial class DriverAssert
for (var i = 0; i < colIndex; i++)
{
runes.InsertRange (i, [_spaceRune]);
strings.InsertRange (i, [_spaceRune.ToString ()]);
}
}
if (runeAtCurrentLocation.GetColumns () > 1)
if (textAtCurrentLocation.GetColumns () > 1)
{
colIndex++;
}
@@ -245,18 +245,13 @@ internal partial class DriverAssert
if (x > -1)
{
runes.Add (runeAtCurrentLocation);
strings.Add (textAtCurrentLocation);
}
// See Issue #2616
//foreach (var combMark in contents [r, c].CombiningMarks) {
// runes.Add (combMark);
//}
}
if (runes.Count > 0)
if (strings.Count > 0)
{
lines.Add (runes);
lines.Add (strings);
}
}
@@ -270,13 +265,13 @@ internal partial class DriverAssert
}
// Remove trailing whitespace on each line
foreach (List<Rune> row in lines)
foreach (List<string> row in lines)
{
for (int c = row.Count - 1; c >= 0; c--)
{
Rune rune = row [c];
string text = row [c];
if (rune != (Rune)' ' || row.Sum (x => x.GetColumns ()) == w)
if (text != " " || row.Sum (x => x.GetColumns ()) == w)
{
break;
}
@@ -285,7 +280,7 @@ internal partial class DriverAssert
}
}
// Convert Rune list to string
// Convert Text list to string
for (var r = 0; r < lines.Count; r++)
{
var line = StringExtensions.ToString (lines [r]);