From 091eb5a9566177a9174a76171c76080c65bd32a3 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 4 Aug 2022 00:58:58 +0100 Subject: [PATCH 1/5] Changes unit tests to support xunit 2.4.2 upgrade. (#1936) --- UnitTests/ScrollBarViewTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UnitTests/ScrollBarViewTests.cs b/UnitTests/ScrollBarViewTests.cs index 174fcee3f0..b479e1a43c 100644 --- a/UnitTests/ScrollBarViewTests.cs +++ b/UnitTests/ScrollBarViewTests.cs @@ -142,8 +142,8 @@ public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () var v = new ScrollBarView (host, true); var h = new ScrollBarView (host, true); - Assert.Throws (null, () => v.OtherScrollBarView = h); - Assert.Throws (null, () => h.OtherScrollBarView = v); + Assert.Throws (() => v.OtherScrollBarView = h); + Assert.Throws (() => h.OtherScrollBarView = v); } [Fact] @@ -156,8 +156,8 @@ public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () var v = new ScrollBarView (host, false); var h = new ScrollBarView (host, false); - Assert.Throws (null, () => v.OtherScrollBarView = h); - Assert.Throws (null, () => h.OtherScrollBarView = v); + Assert.Throws (() => v.OtherScrollBarView = h); + Assert.Throws (() => h.OtherScrollBarView = v); } [Fact] From e0e644c2632b3957b9d1b143a0ce7a31904b0790 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:11:10 -0700 Subject: [PATCH 2/5] Bump xunit from 2.4.1 to 2.4.2 (#1933) Bumps [xunit](https://github.com/xunit/xunit) from 2.4.1 to 2.4.2. - [Release notes](https://github.com/xunit/xunit/releases) - [Commits](https://github.com/xunit/xunit/compare/2.4.1...2.4.2) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tig Kindel --- UnitTests/UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 0e16f0c530..f3bdb15066 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -21,7 +21,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 3257bd8575724f6b75b1868ea271a3ae24259529 Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Wed, 3 Aug 2022 21:59:14 -0400 Subject: [PATCH 3/5] fixes #1773 - better hotnormal color for listview (#1937) --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 2f5813739d..21b7a60945 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -1411,7 +1411,7 @@ public override void Init (Action terminalResized) Colors.Base.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkBlue); Colors.Base.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); - Colors.Base.HotNormal = MakeColor (ConsoleColor.DarkCyan, ConsoleColor.DarkBlue); + Colors.Base.HotNormal = MakeColor (ConsoleColor.Cyan, ConsoleColor.DarkBlue); Colors.Base.HotFocus = MakeColor (ConsoleColor.Blue, ConsoleColor.Gray); Colors.Base.Disabled = MakeColor (ConsoleColor.DarkGray, ConsoleColor.DarkBlue); From 666c2e151a3039a9823a07e9d15d738669a00dfd Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Thu, 4 Aug 2022 11:26:39 -0400 Subject: [PATCH 4/5] Fix 1773 again (#1938) * fixes #1773 - better hotnormal color for listview * Other drivers * fixed curses driver --- Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs | 2 +- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 1cd4b6dad5..6b5aa1a1a5 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -907,7 +907,7 @@ public override void Init (Action terminalResized) Colors.Base.Normal = MakeColor (Color.White, Color.Blue); Colors.Base.Focus = MakeColor (Color.Black, Color.Gray); - Colors.Base.HotNormal = MakeColor (Color.Cyan, Color.Blue); + Colors.Base.HotNormal = MakeColor (Color.BrightCyan, Color.Blue); Colors.Base.HotFocus = MakeColor (Color.BrightBlue, Color.Gray); Colors.Base.Disabled = MakeColor (Color.DarkGray, Color.Blue); diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index e30e973157..95e93391ab 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -1351,7 +1351,7 @@ public override void Init (Action terminalResized) Colors.Base.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkBlue); Colors.Base.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); - Colors.Base.HotNormal = MakeColor (ConsoleColor.DarkCyan, ConsoleColor.DarkBlue); + Colors.Base.HotNormal = MakeColor (ConsoleColor.Cyan, ConsoleColor.DarkBlue); Colors.Base.HotFocus = MakeColor (ConsoleColor.Blue, ConsoleColor.Gray); Colors.Base.Disabled = MakeColor (ConsoleColor.DarkGray, ConsoleColor.DarkBlue); From a23c1bee194b268f2d3c42a6c673a1fd8ec24e73 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 4 Aug 2022 18:15:21 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Fixes=20#1925.=20Preserve=20trailing=20spac?= =?UTF-8?q?es=20on=20word=20wrap=20must=20be=20refactored=E2=80=A6=20(#192?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes #1925. Preserve trailing spaces on word wrap must be refactored on TextFormatter. * Fixes a bug on Format when the preserveTrailingSpaces is enabled. Co-authored-by: Tig Kindel --- Terminal.Gui/Core/TextFormatter.cs | 21 +++++++--- Terminal.Gui/Views/TextView.cs | 28 +------------- UnitTests/ScrollBarViewTests.cs | 20 +++++----- UnitTests/TextFormatterTests.cs | 61 ++++++++++++++++++++++++++++-- UnitTests/TextViewTests.cs | 43 +++++++++++---------- 5 files changed, 106 insertions(+), 67 deletions(-) diff --git a/Terminal.Gui/Core/TextFormatter.cs b/Terminal.Gui/Core/TextFormatter.cs index f45cbd9495..eb4ec57756 100644 --- a/Terminal.Gui/Core/TextFormatter.cs +++ b/Terminal.Gui/Core/TextFormatter.cs @@ -366,22 +366,28 @@ public List Lines { /// public bool NeedsFormat { get => needsFormat; set => needsFormat = value; } - static ustring StripCRLF (ustring str) + static ustring StripCRLF (ustring str, bool keepNewLine = false) { var runes = str.ToRuneList (); for (int i = 0; i < runes.Count; i++) { switch (runes [i]) { case '\n': - runes.RemoveAt (i); + if (!keepNewLine) { + runes.RemoveAt (i); + } break; case '\r': if ((i + 1) < runes.Count && runes [i + 1] == '\n') { runes.RemoveAt (i); - runes.RemoveAt (i + 1); + if (!keepNewLine) { + runes.RemoveAt (i); + } i++; } else { - runes.RemoveAt (i); + if (!keepNewLine) { + runes.RemoveAt (i); + } } break; } @@ -515,6 +521,7 @@ public static List WordWrap (ustring text, int width, bool preserveTrai int GetNextWhiteSpace (int from, int cWidth, out bool incomplete, int cLength = 0) { + var lastFrom = from; var to = from; var length = cLength; incomplete = false; @@ -552,8 +559,10 @@ int GetNextWhiteSpace (int from, int cWidth, out bool incomplete, int cLength = } to++; } - if (cLength > 0 && to < runes.Count && runes [to] != ' ') { + if (cLength > 0 && to < runes.Count && runes [to] != ' ' && runes [to] != '\t') { return from; + } else if (cLength > 0 && to < runes.Count && (runes [to] == ' ' || runes [to] == '\t')) { + return lastFrom; } else { return to; } @@ -727,7 +736,7 @@ public static List Format (ustring text, int width, bool justify, bool return lineResult; } - var runes = text.ToRuneList (); + var runes = StripCRLF (text, true).ToRuneList (); int runeCount = runes.Count; int lp = 0; for (int i = 0; i < runeCount; i++) { diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 9c135301e6..21ea9a1231 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1519,7 +1519,7 @@ void WrapTextModel () out int nStartRow, out int nStartCol, currentRow, currentColumn, selectionStartRow, selectionStartColumn, - tabWidth, preserveTrailingSpaces: !ReadOnly); + tabWidth, preserveTrailingSpaces: true); currentRow = nRow; currentColumn = nCol; selectionStartRow = nStartRow; @@ -1610,10 +1610,7 @@ public ustring SelectedText { } SetWrapModel (); - var savedCurrentColumn = CurrentColumn; - currentColumn = GetCurrentColumnReadOnyWrapModel (true); var sel = GetRegion (); - currentColumn = savedCurrentColumn; UpdateWrapModel (); Adjust (); @@ -1993,9 +1990,6 @@ public bool ReadOnly { if (value != isReadOnly) { isReadOnly = value; - SetWrapModel (); - currentColumn = GetCurrentColumnReadOnyWrapModel (); - UpdateWrapModel (); SetNeedsDisplay (); Adjust (); } @@ -2316,7 +2310,7 @@ void UpdateWrapModel ([CallerMemberName] string caller = null) wrapManager.UpdateModel (model, out int nRow, out int nCol, out int nStartRow, out int nStartCol, currentRow, currentColumn, - selectionStartRow, selectionStartColumn, preserveTrailingSpaces: !ReadOnly); + selectionStartRow, selectionStartColumn, preserveTrailingSpaces: true); currentRow = nRow; currentColumn = nCol; selectionStartRow = nStartRow; @@ -2327,21 +2321,6 @@ void UpdateWrapModel ([CallerMemberName] string caller = null) throw new InvalidOperationException ($"WordWrap settings was changed after the {currentCaller} call."); } - int GetCurrentColumnReadOnyWrapModel (bool forcePreserveTrailingSpaces = false) - { - if (wordWrap) { - var wManager = new WordWrapManager (wrapManager.Model); - if (ReadOnly && !forcePreserveTrailingSpaces) { - wManager.WrapModel (frameWidth, out _, out _, out _, out _, preserveTrailingSpaces: false); - } else { - wManager.WrapModel (frameWidth, out _, out _, out _, out _, preserveTrailingSpaces: true); - } - var currentLine = wrapManager.GetWrappedLineColWidth (CurrentRow, CurrentColumn, wManager); - return currentLine; - } - return currentColumn; - } - /// public override void Redraw (Rect bounds) { @@ -3803,8 +3782,6 @@ bool DeleteTextBackwards () public void Copy () { SetWrapModel (); - var savedCurrentColumn = CurrentColumn; - currentColumn = GetCurrentColumnReadOnyWrapModel (true); if (selecting) { SetClipboard (GetRegion ()); copyWithoutSelection = false; @@ -3813,7 +3790,6 @@ public void Copy () SetClipboard (ustring.Make (currentLine)); copyWithoutSelection = true; } - currentColumn = savedCurrentColumn; UpdateWrapModel (); DoNeededAction (); } diff --git a/UnitTests/ScrollBarViewTests.cs b/UnitTests/ScrollBarViewTests.cs index b479e1a43c..f4571602c1 100644 --- a/UnitTests/ScrollBarViewTests.cs +++ b/UnitTests/ScrollBarViewTests.cs @@ -745,7 +745,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible () Assert.True (textView.WordWrap); Assert.True (scrollBar.AutoHideScrollBars); Assert.Equal (7, textView.Lines); - Assert.Equal (23, textView.Maxlength); + Assert.Equal (22, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); Assert.Equal (0, scrollBar.OtherScrollBarView.Position); @@ -754,8 +754,8 @@ public void Hosting_ShowBothScrollIndicator_Invisible () │This is the help text │ │for the Second Step. │ │ │ -│Press the button to see │ -│ a message box. │ +│Press the button to │ +│see a message box. │ │ │ │Enter name too. │ │ │ @@ -780,21 +780,21 @@ public void Hosting_ShowBothScrollIndicator_Invisible () Assert.True (textView.WordWrap); Assert.True (scrollBar.AutoHideScrollBars); - Assert.Equal (19, textView.Lines); + Assert.Equal (20, textView.Lines); Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); Assert.Equal (0, scrollBar.OtherScrollBarView.Position); expected = @" ┌ Test ──┐ -│This is▲│ -│ the ┬│ +│This ▲│ +│is the ┬│ │help ││ │text ┴│ -│for the░│ -│ Second░│ -│ Step. ░│ -│ ▼│ +│for ░│ +│the ░│ +│Second ░│ +│Step. ▼│ └────────┘ "; diff --git a/UnitTests/TextFormatterTests.cs b/UnitTests/TextFormatterTests.cs index 4c4119547a..02b07c0a5f 100644 --- a/UnitTests/TextFormatterTests.cs +++ b/UnitTests/TextFormatterTests.cs @@ -2006,10 +2006,33 @@ public void WordWrap_preserveTrailingSpaces () wrappedLines = TextFormatter.WordWrap (text, maxWidth, true); Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.RuneCount)); Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.ConsoleWidth)); - Assert.Equal ("A sentence has", wrappedLines [0].ToString ()); - Assert.Equal (" words.", wrappedLines [1].ToString ()); + Assert.Equal ("A sentence ", wrappedLines [0].ToString ()); + Assert.Equal ("has words.", wrappedLines [1].ToString ()); Assert.True (wrappedLines.Count == 2); + maxWidth = 8; + expectedClippedWidth = 8; + wrappedLines = TextFormatter.WordWrap (text, maxWidth, true); + Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.RuneCount)); + Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.ConsoleWidth)); + Assert.Equal ("A ", wrappedLines [0].ToString ()); + Assert.Equal ("sentence", wrappedLines [1].ToString ()); + Assert.Equal (" has ", wrappedLines [2].ToString ()); + Assert.Equal ("words.", wrappedLines [^1].ToString ()); + Assert.True (wrappedLines.Count == 4); + + maxWidth = 6; + expectedClippedWidth = 6; + wrappedLines = TextFormatter.WordWrap (text, maxWidth, true); + Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.RuneCount)); + Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.ConsoleWidth)); + Assert.Equal ("A ", wrappedLines [0].ToString ()); + Assert.Equal ("senten", wrappedLines [1].ToString ()); + Assert.Equal ("ce ", wrappedLines [2].ToString ()); + Assert.Equal ("has ", wrappedLines [3].ToString ()); + Assert.Equal ("words.", wrappedLines [^1].ToString ()); + Assert.True (wrappedLines.Count == 5); + maxWidth = 3; expectedClippedWidth = 3; wrappedLines = TextFormatter.WordWrap (text, maxWidth, true); @@ -2312,6 +2335,18 @@ public void WordWrap_preserveTrailingSpaces_With_Tab () Assert.Equal ("words.", wrappedLines [2].ToString ()); Assert.True (wrappedLines.Count == 3); + maxWidth = 8; + expectedClippedWidth = 8; + wrappedLines = TextFormatter.WordWrap (text, maxWidth, true, tabWidth); + Assert.True (expectedClippedWidth >= wrappedLines.Max (l => l.RuneCount)); + Assert.Equal ("A ", wrappedLines [0].ToString ()); + Assert.Equal ("sentence", wrappedLines [1].ToString ()); + Assert.Equal ("\t\t", wrappedLines [2].ToString ()); + Assert.Equal ("\t ", wrappedLines [3].ToString ()); + Assert.Equal ("has ", wrappedLines [4].ToString ()); + Assert.Equal ("words.", wrappedLines [^1].ToString ()); + Assert.True (wrappedLines.Count == 6); + maxWidth = 3; expectedClippedWidth = 3; wrappedLines = TextFormatter.WordWrap (text, maxWidth, true, tabWidth); @@ -2873,8 +2908,8 @@ public void Format_WordWrap_preserveTrailingSpaces () Assert.Equal (" A ", list2 [0].ToString ()); Assert.Equal ("sent", list2 [1].ToString ()); Assert.Equal ("ence", list2 [2].ToString ()); - Assert.Equal (" has", list2 [3].ToString ()); - Assert.Equal (" ", list2 [4].ToString ()); + Assert.Equal (" ", list2 [3].ToString ()); + Assert.Equal ("has ", list2 [4].ToString ()); Assert.Equal ("word", list2 [5].ToString ()); Assert.Equal ("s. ", list2 [6].ToString ()); Assert.Equal (" ", list2 [7].ToString ()); @@ -3959,5 +3994,23 @@ public void AutoSize_False_View_Width_Zero_Returns_Minimum_Width_With_Wide_Rune pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new Rect (0, 0, 4, 10), pos); } + + [Fact] + public void Format_With_PreserveTrailingSpaces_And_Without_PreserveTrailingSpaces () + { + var text = $"Line1{Environment.NewLine}Line2{Environment.NewLine}Line3{Environment.NewLine}"; + var width = 60; + var preserveTrailingSpaces = false; + var formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces); + Assert.Equal ("Line1", formated [0]); + Assert.Equal ("Line2", formated [1]); + Assert.Equal ("Line3", formated [^1]); + + preserveTrailingSpaces = true; + formated = TextFormatter.Format (text, width, false, true, preserveTrailingSpaces); + Assert.Equal ("Line1", formated [0]); + Assert.Equal ("Line2", formated [1]); + Assert.Equal ("Line3", formated [^1]); + } } } \ No newline at end of file diff --git a/UnitTests/TextViewTests.cs b/UnitTests/TextViewTests.cs index 2f506ba81f..c618664834 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -1967,17 +1967,16 @@ public void WordWrap_WrapModel_Output () tv.Redraw (tv.Bounds); - string expected = @" + GraphViewTests.AssertDriverContentsWithFrameAre (@" This is -the first - line. +the +first +line. This is -the -second -line. -"; - - GraphViewTests.AssertDriverContentsAre (expected, output); +the +second +line. +", output); } [Fact] @@ -2050,26 +2049,28 @@ public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy () Application.Top.Add (tv); tv.Redraw (tv.Bounds); - GraphViewTests.AssertDriverContentsAre (@" -This is + GraphViewTests.AssertDriverContentsWithFrameAre (@" +This is the first -line. -This is -the second - line. +line. +This is +the +second +line. ", output); tv.ReadOnly = true; tv.CursorPosition = new Point (6, 2); Assert.Equal (new Point (5, 2), tv.CursorPosition); tv.Redraw (tv.Bounds); - GraphViewTests.AssertDriverContentsAre (@" -This is + GraphViewTests.AssertDriverContentsWithFrameAre (@" +This is the first -line. -This is -the second -line. +line. +This is +the +second +line. ", output); tv.SelectionStartRow = 0;