Skip to content

Commit 0436019

Browse files
committed
Fixes gui-cs#2616. Support combining sequences that don't normalize
1 parent 6851b42 commit 0436019

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public void AddRune (Rune rune)
179179
Contents [Row, Col - 1].Attribute = CurrentAttribute;
180180
Contents [Row, Col - 1].IsDirty = true;
181181

182-
//Col--;
182+
if (normalized.Length > 1) {
183+
Contents [Row, Col].Runes = new List<Rune> { (Rune)normalized [1] }; ;
184+
Contents [Row, Col].Attribute = CurrentAttribute;
185+
Contents [Row, Col].IsDirty = true;
186+
}
183187
} else {
184188
Contents [Row, Col].Attribute = CurrentAttribute;
185189
Contents [Row, Col].IsDirty = true;

UnitTests/ConsoleDrivers/ContentsTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@ public ContentsTests (ITestOutputHelper output)
1717
this.output = output;
1818
}
1919

20-
[Theory]
20+
[Theory, AutoInitShutdown]
2121
[InlineData (typeof (FakeDriver))]
2222
//[InlineData (typeof (NetDriver))]
2323
//[InlineData (typeof (CursesDriver))]
2424
//[InlineData (typeof (WindowsDriver))]
2525
public void AddStr_With_Combining_Characters (Type driverType)
2626
{
27-
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
28-
Application.Init (driver);
29-
// driver.Init (null);
27+
Application.Init ();
3028

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

35-
driver.AddStr (combined);
36-
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
37-
38-
#if false // Disabled Until #2616 is fixed
33+
Application.Driver.AddStr (combined);
34+
TestHelpers.AssertDriverContentsAre (expected, output);
3935

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

46-
driver.Move (0, 0);
47-
driver.AddStr (combined);
48-
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
42+
Application.Driver.Move (0, 0);
43+
Application.Driver.AddStr (combined);
44+
TestHelpers.AssertDriverContentsAre (expected, output);
4945

50-
#endif
51-
52-
// Shutdown must be called to safely clean up Application if Init has been called
53-
Application.Shutdown ();
46+
// o + ogonek + acute = <U+0061, U+0328, U+0301> ( ǫ́ )
47+
ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
48+
combined = "o" + ogonek + acuteaccent;
49+
expected = "ǫ́";
50+
51+
Application.Driver.Move (0, 0);
52+
Application.Driver.AddStr (combined);
53+
TestHelpers.AssertDriverContentsAre (expected, output);
5454
}
5555

5656
[Theory]
@@ -91,7 +91,7 @@ public void Move_Bad_Coordinates (Type driverType)
9191
}
9292

9393
// TODO: Add these unit tests
94-
94+
9595
// AddRune moves correctly
9696

9797
// AddRune with wide characters are handled correctly

0 commit comments

Comments
 (0)