Pārlūkot izejas kodu

Fixes #3774. TextModel.ToRuneCellList is internal and is better move it to the public RuneCell class.

BDisp 10 mēneši atpakaļ
vecāks
revīzija
026a20ee7f

+ 1 - 1
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;
     }

+ 2 - 2
Terminal.Gui/Views/TextField.cs

@@ -546,7 +546,7 @@ public class TextField : View
             if (!Secret && !_historyText.IsFromHistory)
             {
                 _historyText.Add (
-                                  new List<List<RuneCell>> { TextModel.ToRuneCellList (oldText) },
+                                  new List<List<RuneCell>> { RuneCell.ToRuneCellList (oldText) },
                                   new Point (_cursorPosition, 0)
                                  );
 
@@ -1342,7 +1342,7 @@ public class TextField : View
 
     private void GenerateSuggestions ()
     {
-        List<RuneCell> currentLine = TextModel.ToRuneCellList (Text);
+        List<RuneCell> currentLine = RuneCell.ToRuneCellList (Text);
         int cursorPosition = Math.Min (CursorPosition, currentLine.Count);
 
         Autocomplete.Context = new AutocompleteContext (

+ 19 - 19
Terminal.Gui/Views/TextView.cs

@@ -42,6 +42,22 @@ public class RuneCell : IEquatable<RuneCell>
 
         return $"U+{Rune.Value:X4} '{Rune.ToString ()}'; {colorSchemeStr}";
     }
+
+    /// <summary>Converts the string into a <see cref="List{RuneCell}"/>.</summary>
+    /// <param name="str">The string to convert.</param>
+    /// <param name="colorScheme">The <see cref="Gui.ColorScheme"/> to use.</param>
+    /// <returns></returns>
+    public static List<RuneCell> ToRuneCellList (string str, ColorScheme? colorScheme = null)
+    {
+        List<RuneCell> 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);
     }
 
-    /// <summary>Converts the string into a <see cref="List{RuneCell}"/>.</summary>
-    /// <param name="str">The string to convert.</param>
-    /// <param name="colorScheme">The <see cref="ColorScheme"/> to use.</param>
-    /// <returns></returns>
-    public static List<RuneCell> ToRuneCellList (string str, ColorScheme? colorScheme = null)
-    {
-        List<RuneCell> 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<RuneCell> runeList = contents is null ? new () : TextModel.ToRuneCellList (contents);
+            List<RuneCell> runeList = contents is null ? new () : RuneCell.ToRuneCellList (contents);
             List<RuneCell> currentLine = GetCurrentLine ();
 
             _historyText.Add (new () { new (currentLine) }, CursorPosition);

+ 1 - 1
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
                                     )
                                );