Fixes #4076 cursor text field (#4077)

* Add test for TextField cursor position

* Add comment and one more assert

* Fix cursor position at the end

* Remove unused local field

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
This commit is contained in:
Thomas Nind
2025-05-11 23:29:22 +01:00
committed by GitHub
parent e0de73ab83
commit ee8f9a8e45
6 changed files with 97 additions and 5 deletions

View File

@@ -24,5 +24,10 @@ internal class FakeOutput : IConsoleOutput
public void SetCursorVisibility (CursorVisibility visibility) { }
/// <inheritdoc/>
public void SetCursorPosition (int col, int row) { }
public void SetCursorPosition (int col, int row) { CursorPosition = new Point (col, row); }
/// <summary>
/// The last value set by calling <see cref="SetCursorPosition"/>
/// </summary>
public Point CursorPosition { get; private set; }
}

View File

@@ -706,10 +706,14 @@ public class GuiTestContext : IDisposable
/// is found (of Type T) or all views are looped through (back to the beginning)
/// in which case triggers hard stop and Exception
/// </summary>
/// <param name="evaluator">Delegate that returns true if the passed View is the one
/// you are trying to focus. Leave <see langword="null"/> to focus the first view of type
/// <typeparamref name="T"/></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public GuiTestContext Focus<T> (Func<T, bool> evaluator) where T : View
public GuiTestContext Focus<T> (Func<T, bool>? evaluator = null) where T : View
{
evaluator ??= _ => true;
Toplevel? t = Application.Top;
HashSet<View> seen = new ();
@@ -816,4 +820,13 @@ public class GuiTestContext : IDisposable
return this;
}
/// <summary>
/// Returns the last set position of the cursor.
/// </summary>
/// <returns></returns>
public Point GetCursorPosition ()
{
return _output.CursorPosition;
}
}