Skip to content

Commit

Permalink
Fixes gui-cs#2616. Support combining sequences that don't normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Oct 24, 2023
1 parent 6851b42 commit 0436019
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
6 changes: 5 additions & 1 deletion Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ public void AddRune (Rune rune)
Contents [Row, Col - 1].Attribute = CurrentAttribute;
Contents [Row, Col - 1].IsDirty = true;

//Col--;
if (normalized.Length > 1) {
Contents [Row, Col].Runes = new List<Rune> { (Rune)normalized [1] }; ;
Contents [Row, Col].Attribute = CurrentAttribute;
Contents [Row, Col].IsDirty = true;
}
} else {
Contents [Row, Col].Attribute = CurrentAttribute;
Contents [Row, Col].IsDirty = true;
Expand Down
36 changes: 18 additions & 18 deletions UnitTests/ConsoleDrivers/ContentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ public ContentsTests (ITestOutputHelper output)
this.output = output;
}

[Theory]
[Theory, AutoInitShutdown]
[InlineData (typeof (FakeDriver))]
//[InlineData (typeof (NetDriver))]
//[InlineData (typeof (CursesDriver))]
//[InlineData (typeof (WindowsDriver))]
public void AddStr_With_Combining_Characters (Type driverType)
{
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
Application.Init (driver);
// driver.Init (null);
Application.Init ();

var acuteaccent = new System.Text.Rune (0x0301); // Combining acute accent (é)
var combined = "e" + acuteaccent;
var expected = "é";

driver.AddStr (combined);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);

#if false // Disabled Until #2616 is fixed
Application.Driver.AddStr (combined);
TestHelpers.AssertDriverContentsAre (expected, output);

// 3 char combine
// a + ogonek + acute = <U+0061, U+0328, U+0301> ( ǫ́ )
// a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
var ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
combined = "a" + ogonek + acuteaccent;
expected = "ǫ́";
expected = "ą́";

driver.Move (0, 0);
driver.AddStr (combined);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.Driver.Move (0, 0);
Application.Driver.AddStr (combined);
TestHelpers.AssertDriverContentsAre (expected, output);

#endif

// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
// o + ogonek + acute = <U+0061, U+0328, U+0301> ( ǫ́ )
ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
combined = "o" + ogonek + acuteaccent;
expected = "ǫ́";

Application.Driver.Move (0, 0);
Application.Driver.AddStr (combined);
TestHelpers.AssertDriverContentsAre (expected, output);
}

[Theory]
Expand Down Expand Up @@ -91,7 +91,7 @@ public void Move_Bad_Coordinates (Type driverType)
}

// TODO: Add these unit tests

// AddRune moves correctly

// AddRune with wide characters are handled correctly
Expand Down

0 comments on commit 0436019

Please sign in to comment.