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

This commit is contained in:
BDisp
2024-10-02 14:14:02 +01:00
parent e4d30a1fe1
commit 026a20ee7f
4 changed files with 23 additions and 23 deletions

View File

@@ -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;
}

View File

@@ -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 (

View File

@@ -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);

View File

@@ -254,7 +254,7 @@ This an long line and against TextView.",
ac.GenerateSuggestions (
new (
TextModel.ToRuneCellList (tv.Text),
RuneCell.ToRuneCellList (tv.Text),
2
)
);