mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* 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:
@@ -1118,7 +1118,8 @@ public class TextField : View, IDesignable
|
||||
break;
|
||||
}
|
||||
|
||||
int cols = _text [idx].GetColumns ();
|
||||
int cols = Math.Max (_text [idx].GetColumns (), 1);
|
||||
|
||||
TextModel.SetCol (ref col, Viewport.Width - 1, cols);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user