From 0436019728975e93e24bc342cf3667b783012462 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 24 Oct 2023 22:38:53 +0100 Subject: [PATCH] Fixes #2616. Support combining sequences that don't normalize --- Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs | 6 +++- UnitTests/ConsoleDrivers/ContentsTests.cs | 36 ++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 042a10bb24..60396f5ee3 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -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)normalized [1] }; ; + Contents [Row, Col].Attribute = CurrentAttribute; + Contents [Row, Col].IsDirty = true; + } } else { Contents [Row, Col].Attribute = CurrentAttribute; Contents [Row, Col].IsDirty = true; diff --git a/UnitTests/ConsoleDrivers/ContentsTests.cs b/UnitTests/ConsoleDrivers/ContentsTests.cs index 2bd0a10b45..f0aec48e8a 100644 --- a/UnitTests/ConsoleDrivers/ContentsTests.cs +++ b/UnitTests/ConsoleDrivers/ContentsTests.cs @@ -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 = ( ǫ́ ) + // a + ogonek + acute = ( ą́ ) 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 = ( ǫ́ ) + 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] @@ -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