From 026a20ee7fcec4ffbdb8ae91fe5774eb34073f7c Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 2 Oct 2024 14:14:02 +0100 Subject: [PATCH] Fixes #3774. TextModel.ToRuneCellList is internal and is better move it to the public RuneCell class. --- .../Views/AutocompleteFilepathContext.cs | 2 +- Terminal.Gui/Views/TextField.cs | 4 +- Terminal.Gui/Views/TextView.cs | 38 +++++++++---------- UnitTests/Text/AutocompleteTests.cs | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Terminal.Gui/Views/AutocompleteFilepathContext.cs b/Terminal.Gui/Views/AutocompleteFilepathContext.cs index f577e554f..96ce1dfae 100644 --- a/Terminal.Gui/Views/AutocompleteFilepathContext.cs +++ b/Terminal.Gui/Views/AutocompleteFilepathContext.cs @@ -6,7 +6,7 @@ namespace Terminal.Gui; internal class AutocompleteFilepathContext : AutocompleteContext { public AutocompleteFilepathContext (string currentLine, int cursorPosition, FileDialogState state) - : base (TextModel.ToRuneCellList (currentLine), cursorPosition) + : base (RuneCell.ToRuneCellList (currentLine), cursorPosition) { State = state; } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 88d2d9348..aa4322e2e 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -546,7 +546,7 @@ public class TextField : View if (!Secret && !_historyText.IsFromHistory) { _historyText.Add ( - new List> { TextModel.ToRuneCellList (oldText) }, + new List> { RuneCell.ToRuneCellList (oldText) }, new Point (_cursorPosition, 0) ); @@ -1342,7 +1342,7 @@ public class TextField : View private void GenerateSuggestions () { - List currentLine = TextModel.ToRuneCellList (Text); + List currentLine = RuneCell.ToRuneCellList (Text); int cursorPosition = Math.Min (CursorPosition, currentLine.Count); Autocomplete.Context = new AutocompleteContext ( diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 78f3bea18..5c4a82fd8 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -42,6 +42,22 @@ public class RuneCell : IEquatable return $"U+{Rune.Value:X4} '{Rune.ToString ()}'; {colorSchemeStr}"; } + + /// Converts the string into a . + /// The string to convert. + /// The to use. + /// + public static List ToRuneCellList (string str, ColorScheme? colorScheme = null) + { + List cells = new (); + + foreach (Rune rune in str.EnumerateRunes ()) + { + cells.Add (new () { Rune = rune, ColorScheme = colorScheme }); + } + + return cells; + } } internal class TextModel @@ -233,22 +249,6 @@ internal class TextModel return SplitNewLines (cells); } - /// Converts the string into a . - /// The string to convert. - /// The to use. - /// - public static List ToRuneCellList (string str, ColorScheme? colorScheme = null) - { - List cells = new (); - - foreach (Rune rune in str.EnumerateRunes ()) - { - cells.Add (new () { Rune = rune, ColorScheme = colorScheme }); - } - - return cells; - } - public override string ToString () { var sb = new StringBuilder (); @@ -855,7 +855,7 @@ internal class TextModel found = true; } - _lines [i] = ToRuneCellList (ReplaceText (x, textToReplace!, matchText, col)); + _lines [i] = RuneCell.ToRuneCellList (ReplaceText (x, textToReplace!, matchText, col)); x = _lines [i]; txt = GetText (x); pos = new (col, i); @@ -1706,7 +1706,7 @@ internal class WordWrapManager foreach (string text in textList) { - runesList.Add (TextModel.ToRuneCellList (text)); + runesList.Add (RuneCell.ToRuneCellList (text)); } return runesList; @@ -3715,7 +3715,7 @@ public class TextView : View if (_copyWithoutSelection && contents.FirstOrDefault (x => x == '\n' || x == '\r') == 0) { - List runeList = contents is null ? new () : TextModel.ToRuneCellList (contents); + List runeList = contents is null ? new () : RuneCell.ToRuneCellList (contents); List currentLine = GetCurrentLine (); _historyText.Add (new () { new (currentLine) }, CursorPosition); diff --git a/UnitTests/Text/AutocompleteTests.cs b/UnitTests/Text/AutocompleteTests.cs index c7d907e1a..1689c70c8 100644 --- a/UnitTests/Text/AutocompleteTests.cs +++ b/UnitTests/Text/AutocompleteTests.cs @@ -254,7 +254,7 @@ This an long line and against TextView.", ac.GenerateSuggestions ( new ( - TextModel.ToRuneCellList (tv.Text), + RuneCell.ToRuneCellList (tv.Text), 2 ) );