Fixes #4442. TextField PositionCursor doesn't treat zero width as one column (#4443)

* Fixes #4442. TextField PositionCursor doesn't treat zero width as one column

* Each character must return at least one column, with the exception of Tab.

* Add unit test for the ScrollOffset
This commit is contained in:
BDisp
2025-12-05 00:12:52 +00:00
committed by GitHub
parent 06767193fb
commit 241aec0e3d
2 changed files with 44 additions and 1 deletions

View File

@@ -632,4 +632,46 @@ public class TextFieldTests (ITestOutputHelper output) : FakeDriverBase
return sb.ToString ();
}
}
[Fact]
public void PositionCursor_Treat_Zero_Width_As_One_Column ()
{
IDriver driver = CreateFakeDriver ();
TextField tf = new () { Width = 10, Text = "\u001B[" };
tf.Driver = driver;
tf.SetRelativeLayout (new (10, 1));
Assert.Equal (0, tf.CursorPosition);
tf.CursorPosition = 1;
Assert.Equal (new Point (1, 0), tf.PositionCursor ());
tf.CursorPosition = 2;
Assert.Equal (new Point (2, 0), tf.PositionCursor ());
}
[Fact]
public void ScrollOffset_Treat_Negative_Width_As_One_Column ()
{
View view = new () { Width = 10, Height = 1};
TextField tf = new () { Width = 2, Text = "\u001B[" };
view.Add (tf);
tf.SetRelativeLayout (new (10, 1));
Assert.Equal (0, tf.ScrollOffset);
Assert.Equal (0, tf.CursorPosition);
Assert.True (tf.NewKeyDownEvent (Key.CursorRight));
Assert.Equal (0, tf.ScrollOffset);
Assert.Equal (1, tf.CursorPosition);
Assert.True (tf.NewKeyDownEvent (Key.CursorRight));
Assert.Equal (1, tf.ScrollOffset);
Assert.Equal (2, tf.CursorPosition);
Assert.False (tf.NewKeyDownEvent (Key.CursorRight));
Assert.Equal (1, tf.ScrollOffset);
Assert.Equal (2, tf.CursorPosition);
}
}