mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Fixed being able to position the cursor vertically if placeholder text was visible and multi-line. This is because the code was using line break info for the place holder. On top of not being correct behavior, this caused further exceptions since the cursor would get outside the editable text rope. Fixed index exception if you try to move left in an empty text edit. Has regression tests. Fixes #4957, fixes #4953
53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System.Numerics;
|
|
using NUnit.Framework;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.UnitTesting.Client.UserInterface.Controls;
|
|
|
|
[TestFixture]
|
|
[TestOf(typeof(TextEdit))]
|
|
public sealed class TextEditTest : RobustUnitTest
|
|
{
|
|
public override UnitTestProject Project => UnitTestProject.Client;
|
|
|
|
[OneTimeSetUp]
|
|
public void Setup()
|
|
{
|
|
IoCManager.Resolve<IUserInterfaceManagerInternal>().InitializeTesting();
|
|
}
|
|
|
|
// Regression test for https://github.com/space-wizards/RobustToolbox/issues/4953
|
|
// It was possible to move the cursor up/down if there was multi-line placeholder text.
|
|
[Test]
|
|
public void TestInvalidMoveInPlaceholder()
|
|
{
|
|
var textEdit = new TextEdit { Placeholder = new Rope.Leaf("Foo\nBar") };
|
|
textEdit.Arrange(new UIBox2(0, 0, 200, 200));
|
|
|
|
var click = new GUIBoundKeyEventArgs(EngineKeyFunctions.TextCursorDown, BoundKeyState.Down, new ScreenCoordinates(), true, Vector2.Zero, Vector2.Zero);
|
|
textEdit.KeyBindDown(click);
|
|
textEdit.KeyBindUp(click);
|
|
|
|
Assert.That(textEdit.CursorPosition.Index, Is.Zero);
|
|
}
|
|
|
|
// Regression test for https://github.com/space-wizards/RobustToolbox/issues/4957
|
|
// Moving left (with the arrow keys) in an empty TextEdit would cause an exception.
|
|
[Test]
|
|
public void TestEmptyMoveLeft()
|
|
{
|
|
var textEdit = new TextEdit();
|
|
textEdit.Arrange(new UIBox2(0, 0, 200, 200));
|
|
|
|
var click = new GUIBoundKeyEventArgs(EngineKeyFunctions.TextCursorLeft, BoundKeyState.Down, new ScreenCoordinates(), true, Vector2.Zero, Vector2.Zero);
|
|
textEdit.KeyBindDown(click);
|
|
textEdit.KeyBindUp(click);
|
|
}
|
|
}
|