public TextEditPage() : base("Text Edit Widget") { FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); BackgroundColor = new RGBA_Bytes(210, 210, 255); topToBottom.Padding = new BorderDouble(20); topToBottom.AddChild(new TextWidget("testing underline jpqy", underline: true)); topToBottom.AddChild(new TextWidget("testing1\ntest2\ntest3")); topToBottom.AddChild(new TextWidget("this is some multiline\ntext\nwith centering", justification: Justification.Center)); int tabIndex = 0; #if true InternalTextEditWidget internalMultiLine = new InternalTextEditWidget("line1\nline2\nline3", 12, true, tabIndex++); //InternalTextEditWidget internalMultiLine = new InternalTextEditWidget("Line 1 - Multi Line Text Control\nLine 2 - Multi Line Text Control\nLine 3 - Multi Line Text Control\n", 12, true); topToBottom.AddChild(internalMultiLine); #endif // show some masking for passwords { FlowLayoutWidget leftToRight = new FlowLayoutWidget(); leftToRight.Margin = new BorderDouble(3); TextEditWidget passwordeTextEdit = new TextEditWidget("Password", tabIndex: tabIndex++); //passwordeTextEdit.InternalTextEditWidget.MaskCharacter = '*'; passwordeTextEdit.Margin = new BorderDouble(4, 0); leftToRight.AddChild(passwordeTextEdit); TextWidget description = new TextWidget("Content:"); leftToRight.AddChild(description); TextWidget passwordContent = new TextWidget("Password"); leftToRight.AddChild(passwordContent); passwordeTextEdit.TextChanged += (sender, e) => { passwordContent.Text = passwordeTextEdit.Text; }; topToBottom.AddChild(leftToRight); } TextEditWidget singleLineTextEdit = new TextEditWidget("Single Line Edit Text Control", tabIndex: tabIndex++); topToBottom.AddChild(singleLineTextEdit); TextEditWidget multiLineTextConrol = new TextEditWidget("Line 1 - Multi Line Text Control\nLine 2 - Multi Line Text Control\nLine 3 - Multi Line Text Control\n", tabIndex: tabIndex++); multiLineTextConrol.Multiline = true; topToBottom.AddChild(multiLineTextConrol); TextEditWidget longTextWidget = new TextEditWidget("This is some really long text.", pixelWidth: 100, tabIndex: tabIndex++); topToBottom.AddChild(longTextWidget); topToBottom.AddChild(new TextWidget("Integer Text Control:")); topToBottom.AddChild(new NumberEdit(512102416, tabIndex: tabIndex++)); topToBottom.AddChild(new TextWidget("Floating Point Text Control:")); topToBottom.AddChild(new NumberEdit(512102416, allowNegatives: true, allowDecimals: true, tabIndex: tabIndex++)); TextWidget paddingAdjustText = new TextWidget("Padding: 0"); paddingAdjustText.AutoExpandBoundsToText = true; topToBottom.AddChild(paddingAdjustText); TextEditWidget paddingAdjustTextEdit = new TextEditWidget("Edit With Padding", tabIndex: tabIndex++); GuiWidget paddingAroundTextEdit = new GuiWidget(100, 16); topToBottom.AddChild(paddingAroundTextEdit); paddingAroundTextEdit.AddChild(paddingAdjustTextEdit); paddingAdjustText.SetBoundsToEncloseChildren(); //AddChild(new TextEditWidget("Multiline Edit Text Widget line 1\nline 2\nline 3", 200, 400, 200, 80, multiLine: true)); AddChild(topToBottom); foreach (GuiWidget child in topToBottom.Children) { //child.Padding = new BorderDouble(4); child.HAnchor = UI.HAnchor.ParentCenter; child.BackgroundColor = RGBA_Bytes.White; //child.Margin = new BorderDouble(3); if (child is TextWidget) { child.BackgroundColor = new RGBA_Bytes(255, 200, 200); } } Slider textPaddingSlider = new Slider(new Vector2(), 200, 0, 10); topToBottom.AddChild(textPaddingSlider); textPaddingSlider.ValueChanged += (sender, e) => { double padding = ((Slider)sender).Value; paddingAdjustText.Padding = new BorderDouble(padding); paddingAroundTextEdit.Padding = new BorderDouble(padding); paddingAroundTextEdit.SetBoundsToEncloseChildren(); ((Slider)sender).Parent.SetBoundsToEncloseChildren(); }; topToBottom.HAnchor = UI.HAnchor.ParentCenter; topToBottom.VAnchor = UI.VAnchor.ParentCenter; }
public void MultiLineTests() { { var singleLine = new InternalTextEditWidget("test", 12, false, 0); var multiLine = new InternalTextEditWidget("test\ntest\ntest", 12, true, 0); Assert.IsTrue(multiLine.Height >= singleLine.Height * 3); } // we get the typed results we expect { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("\n\n\n\n", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 4); Assert.IsTrue(multiLine.Text == "\n\n\n\n"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\n\na"); SendKey(Keys.Up, ' ', container); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 0); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "a\n\n\na\na"); SendKey(Keys.Down, ' ', container); SendKey(Keys.A | Keys.Shift, 'A', container); Assert.IsTrue(multiLine.Text == "a\nA\n\na\na"); container.Close(); } // make sure the insert position is correct when homed { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("line1\nline2\nline3", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "line1\nline2\naline3"); SendKey(Keys.Back, ' ', container); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); container.Close(); } // make sure the insert position is correct when move left to end of line { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("xx", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.X == 0); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.X == 0); SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); double leftOne = multiLine.InsertBarPosition.X; SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.X == leftOne * 2); container.Close(); } // make sure the cursor is at the right hight when it is after a \n that is on the first line { var container = new GuiWidget { DoubleBuffer = true, LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("\n1\n\n3\n", 12, true, 0); Assert.IsTrue(multiLine.LocalBounds.Height == 16 * 5); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.Y == 0); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); Assert.IsTrue(multiLine.InsertBarPosition.Y == -16); // move past 1 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.Y == -16); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 3); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 4); Assert.IsTrue(multiLine.InsertBarPosition.Y == -48); // move past 3 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 5); Assert.IsTrue(multiLine.InsertBarPosition.Y == -48); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 6); Assert.IsTrue(multiLine.InsertBarPosition.Y == -64); container.Close(); } }
public void MiltiLineTests() { { InternalTextEditWidget singleLine = new InternalTextEditWidget("test", 12, false, 0); InternalTextEditWidget multiLine = new InternalTextEditWidget("test\ntest\ntest", 12, true, 0); Assert.IsTrue(multiLine.Height >= singleLine.Height * 3); } // we get the typed results we expect { GuiWidget container = new GuiWidget(); container.LocalBounds = new RectangleDouble(0, 0, 200, 200); InternalTextEditWidget multiLine = new InternalTextEditWidget("\n\n\n\n", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 4); Assert.IsTrue(multiLine.Text == "\n\n\n\n"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\n\na"); SendKey(Keys.Up, ' ', container); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 0); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "a\n\n\na\na"); SendKey(Keys.Down, ' ', container); SendKey(Keys.A | Keys.Shift, 'A', container); Assert.IsTrue(multiLine.Text == "a\nA\n\na\na"); container.Close(); } // make sure the insert position is correct when homed { GuiWidget container = new GuiWidget(); container.LocalBounds = new RectangleDouble(0, 0, 200, 200); InternalTextEditWidget multiLine = new InternalTextEditWidget("line1\nline2\nline3", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.InsertBarPosition.y == -32); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.InsertBarPosition.y == -32); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "line1\nline2\naline3"); SendKey(Keys.Back, ' ', container); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); Assert.IsTrue(multiLine.InsertBarPosition.y == -32); container.Close(); } // make sure the insert position is correct when move left to end of line { GuiWidget container = new GuiWidget(); container.LocalBounds = new RectangleDouble(0, 0, 200, 200); InternalTextEditWidget multiLine = new InternalTextEditWidget("xx", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.x == 0); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.x == 0); SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); double leftOne = multiLine.InsertBarPosition.x; SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.x == leftOne * 2); container.Close(); } // make sure the cursor is at the right hight when it is after a \n that is on the first line { GuiWidget container = new GuiWidget(); container.DoubleBuffer = true; container.LocalBounds = new RectangleDouble(0, 0, 200, 200); InternalTextEditWidget multiLine = new InternalTextEditWidget("\n1\n\n3\n", 12, true, 0); Assert.IsTrue(multiLine.LocalBounds.Height == 16 * 5); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.y == 0); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); Assert.IsTrue(multiLine.InsertBarPosition.y == -16); // move past 1 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.y == -16); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 3); Assert.IsTrue(multiLine.InsertBarPosition.y == -32); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 4); Assert.IsTrue(multiLine.InsertBarPosition.y == -48); // move past 3 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 5); Assert.IsTrue(multiLine.InsertBarPosition.y == -48); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 6); Assert.IsTrue(multiLine.InsertBarPosition.y == -64); container.Close(); } }
public void MultiLineTests() { // make sure selection ranges are always working { Clipboard.SetSystemClipboard(new SimulatedClipboard()); var singleLine = new InternalTextEditWidget("test", 12, false, 0); void TestRange(int start, int end, string expected) { singleLine.CharIndexToInsertBefore = start; singleLine.SelectionIndexToStartBefore = end; singleLine.Selecting = true; Assert.AreEqual(expected, singleLine.Selection); singleLine.CopySelection(); Assert.AreEqual(expected, Clipboard.Instance.GetText()); } // ask for some selections TestRange(-10, -8, ""); TestRange(-8, -10, ""); TestRange(18, 10, ""); TestRange(10, 18, ""); TestRange(2, -10, "te"); TestRange(-10, 2, "te"); TestRange(18, 2, "st"); TestRange(3, 22, "t"); } { var singleLine = new InternalTextEditWidget("test", 12, false, 0); var multiLine = new InternalTextEditWidget("test\ntest\ntest", 12, true, 0); Assert.IsTrue(multiLine.Height >= singleLine.Height * 3); } // we get the typed results we expect { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("\n\n\n\n", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 4); Assert.IsTrue(multiLine.Text == "\n\n\n\n"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\n\na"); SendKey(Keys.Up, ' ', container); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.SelectionIndexToStartBefore == 0); Assert.IsTrue(multiLine.Text == "\n\n\na\na"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "a\n\n\na\na"); SendKey(Keys.Down, ' ', container); SendKey(Keys.A | Keys.Shift, 'A', container); Assert.IsTrue(multiLine.Text == "a\nA\n\na\na"); container.Close(); } // make sure the insert position is correct when homed { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("line1\nline2\nline3", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); SendKey(Keys.A, 'a', container); Assert.IsTrue(multiLine.Text == "line1\nline2\naline3"); SendKey(Keys.Back, ' ', container); Assert.IsTrue(multiLine.Text == "line1\nline2\nline3"); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); container.Close(); } // make sure the insert position is correct when move left to end of line { var container = new GuiWidget { LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("xx", 12, true, 0); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); Assert.IsTrue(multiLine.ContainsFocus == true); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.X == 0); SendKey(Keys.Home, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.X == 0); SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); double leftOne = multiLine.InsertBarPosition.X; SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.X == leftOne * 2); container.Close(); } // make sure the cursor is at the right hight when it is after a \n that is on the first line { var container = new GuiWidget { DoubleBuffer = true, LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var multiLine = new InternalTextEditWidget("\n1\n\n3\n", 12, true, 0); Assert.IsTrue(multiLine.LocalBounds.Height == 16 * 5); container.AddChild(multiLine); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, multiLine.Height - 1, 0)); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 0); Assert.IsTrue(multiLine.InsertBarPosition.Y == 0); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 1); Assert.IsTrue(multiLine.InsertBarPosition.Y == -16); // move past 1 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 2); Assert.IsTrue(multiLine.InsertBarPosition.Y == -16); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 3); Assert.IsTrue(multiLine.InsertBarPosition.Y == -32); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 4); Assert.IsTrue(multiLine.InsertBarPosition.Y == -48); // move past 3 SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 5); Assert.IsTrue(multiLine.InsertBarPosition.Y == -48); // move past \n SendKey(Keys.Right, ' ', container); Assert.IsTrue(multiLine.CharIndexToInsertBefore == 6); Assert.IsTrue(multiLine.InsertBarPosition.Y == -64); container.Close(); } }
public void TextEditingSpecialKeysWork() { var container = new GuiWidget { DoubleBuffer = true, LocalBounds = new RectangleDouble(0, 0, 200, 200) }; var textEdit = new TextEditWidget("some starting text"); container.AddChild(textEdit); container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, textEdit.Height - 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, textEdit.Height - 1, 0)); Assert.IsTrue(textEdit.CharIndexToInsertBefore == 0); Assert.IsTrue(textEdit.TopLeftOffset.Y == 0); // test that we move to the next character correctly Assert.AreEqual(4, InternalTextEditWidget.IndexOfNextToken("235 12/6", 0)); Assert.AreEqual(6, InternalTextEditWidget.IndexOfNextToken("235 12/6", 0)); Assert.AreEqual(3, InternalTextEditWidget.IndexOfNextToken("235\n 12/6", 0)); Assert.AreEqual(7, InternalTextEditWidget.IndexOfNextToken("235\n 12/6", 3)); Assert.AreEqual(4, InternalTextEditWidget.IndexOfNextToken("235\n\n 12/6", 3)); Assert.AreEqual(8, InternalTextEditWidget.IndexOfNextToken("235\n\n 12/6", 4)); Assert.AreEqual(3, InternalTextEditWidget.IndexOfNextToken("123+ 235 12/6", 0)); Assert.AreEqual(3, InternalTextEditWidget.IndexOfNextToken("235+12/6", 0)); Assert.AreEqual(5, InternalTextEditWidget.IndexOfNextToken("+++++235 12/6", 0)); Assert.AreEqual(5, InternalTextEditWidget.IndexOfNextToken("+++++235 12/6", 0)); // test that we move to the previous character correctly Assert.AreEqual(7, InternalTextEditWidget.IndexOfPreviousToken("=35+12/6", 8)); Assert.AreEqual(6, InternalTextEditWidget.IndexOfPreviousToken("35556+68384734", 10)); Assert.AreEqual(5, InternalTextEditWidget.IndexOfPreviousToken("35556+68384734", 6)); Assert.AreEqual(0, InternalTextEditWidget.IndexOfPreviousToken("35556+68384734", 5)); Assert.AreEqual(11, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 12)); Assert.AreEqual(10, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 11)); Assert.AreEqual(8, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 10)); Assert.AreEqual(5, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 8)); Assert.AreEqual(4, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 5)); Assert.AreEqual(0, InternalTextEditWidget.IndexOfPreviousToken("235\n\n 12/6", 4)); Assert.AreEqual(0, InternalTextEditWidget.IndexOfPreviousToken("some starting text", 5)); void RunWithSpecificChar(string sep, string first, string second, string third) { var startText = $"{first}{sep}{second}{sep}{third}"; Assert.IsTrue(textEdit.Text == startText); // this is to select some text SendKey(Keys.Shift | Keys.Control | Keys.Right, ' ', container); Assert.IsTrue(textEdit.Selection == first + sep); Assert.IsTrue(textEdit.Text == startText); // this is to prove that we don't loose the selection when pressing Control SendKeyDown(Keys.Control, container); Assert.IsTrue(textEdit.Selection == first + sep); Assert.IsTrue(textEdit.Text == startText); // this is to prove that we don't loose the selection when pressing Shift SendKeyDown(Keys.Shift, container); Assert.IsTrue(textEdit.Text == startText); Assert.IsTrue(textEdit.Selection == first + sep); SendKeyDown(Keys.Right, container); Assert.IsTrue(textEdit.Selection == ""); SendKey(Keys.Shift | Keys.Control | Keys.Left, ' ', container); Assert.IsTrue(textEdit.Selection == first + sep); SendKey(Keys.Delete, ' ', container); Assert.IsTrue(textEdit.Text == $"{second}{sep}{third}"); SendKey(Keys.Shift | Keys.Control | Keys.Right, ' ', container); Assert.IsTrue(textEdit.Selection == $"{second}{sep}"); // if this fails add // GuiHalWidget.SetClipboardFunctions(System.Windows.Forms.Clipboard.GetText, System.Windows.Forms.Clipboard.SetText, System.Windows.Forms.Clipboard.ContainsText); // before you call the unit tests Clipboard.SetSystemClipboard(new WindowsFormsClipboard()); SendKey(Keys.Control | Keys.C, 'c', container); Assert.IsTrue(textEdit.Selection == $"{second}{sep}"); Assert.IsTrue(textEdit.Text == $"{second}{sep}{third}"); SendKeyDown(Keys.Right, container); // move to the right SendKey(Keys.Control | Keys.V, 'v', container); Assert.IsTrue(textEdit.Text == $"{second}{sep}{second}{sep}{third}"); } void CheckChar(string sep) { textEdit.Text = $"some{sep}starting{sep}text"; // spaces work as expected RunWithSpecificChar(sep, "some", "starting", "text"); textEdit.Text = $"123{sep}is{sep}number"; RunWithSpecificChar(sep, "123", "is", "number"); textEdit.Text = $"123_1{sep}456_2{sep}789_3"; RunWithSpecificChar(sep, "123_1", "456_2", "789_3"); } CheckChar(" "); container.Close(); }