From c350886b5d3771d780129cbcb1a4fdf55d35b734 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 18 Sep 2022 00:28:31 +0100 Subject: [PATCH 1/5] Fixes #2047. Tests are failing locally after merging #2046 --- Terminal.Gui/Core/Clipboard/Clipboard.cs | 6 +- Terminal.Gui/Core/View.cs | 2 +- Terminal.Gui/Views/TextField.cs | 4 +- UnitTests/ClipboardTests.cs | 12 +- UnitTests/TextFieldTests.cs | 472 ++++---- UnitTests/TextViewTests.cs | 1288 +++++++++++----------- 6 files changed, 907 insertions(+), 877 deletions(-) diff --git a/Terminal.Gui/Core/Clipboard/Clipboard.cs b/Terminal.Gui/Core/Clipboard/Clipboard.cs index 89610b830..910470a86 100644 --- a/Terminal.Gui/Core/Clipboard/Clipboard.cs +++ b/Terminal.Gui/Core/Clipboard/Clipboard.cs @@ -15,7 +15,11 @@ namespace Terminal.Gui { get { try { if (IsSupported) { - return Application.Driver.Clipboard.GetClipboardData (); + var clip = ustring.Make (Application.Driver.Clipboard.GetClipboardData ()); + if (clip != null) { + return contents = clip; + } + return clip; } else { return contents; } diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index dd7a52f4d..99afe4b07 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -2722,7 +2722,7 @@ namespace Terminal.Gui { /// The text formatter size more the length. public Size GetBoundsTextFormatterSize () { - if (TextFormatter.Text == null) + if (ustring.IsNullOrEmpty (TextFormatter.Text)) return Bounds.Size; return new Size (frame.Size.Width + GetHotKeySpecifierLength (), diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index dba4130bf..3f9ae85f0 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -666,7 +666,7 @@ namespace Terminal.Gui { historyText.Redo (); - //if (Clipboard.Contents == null) + //if (ustring.IsNullOrEmpty (Clipboard.Contents)) // return true; //var clip = TextModel.ToRunes (Clipboard.Contents); //if (clip == null) @@ -1217,7 +1217,7 @@ namespace Terminal.Gui { /// public virtual void Paste () { - if (ReadOnly || Clipboard.Contents == null) { + if (ReadOnly || ustring.IsNullOrEmpty (Clipboard.Contents)) { return; } diff --git a/UnitTests/ClipboardTests.cs b/UnitTests/ClipboardTests.cs index 2276e7358..cb2287aaa 100644 --- a/UnitTests/ClipboardTests.cs +++ b/UnitTests/ClipboardTests.cs @@ -8,14 +8,16 @@ namespace Terminal.Gui.Core { [AutoInitShutdown] public void Contents_Gets_Sets () { - var clipText = "This is a clipboard unit test."; - Clipboard.Contents = clipText; + lock (Clipboard.Contents) { + var clipText = "This is a clipboard unit test."; + Clipboard.Contents = clipText; - Application.Iteration += () => Application.RequestStop (); + Application.Iteration += () => Application.RequestStop (); - Application.Run (); + Application.Run (); - Assert.Equal (clipText, Clipboard.Contents); + Assert.Equal (clipText, Clipboard.Contents); + } } [Fact] diff --git a/UnitTests/TextFieldTests.cs b/UnitTests/TextFieldTests.cs index 3fcd92f44..6d38fef32 100644 --- a/UnitTests/TextFieldTests.cs +++ b/UnitTests/TextFieldTests.cs @@ -584,38 +584,42 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Or_Cut_And_Paste_With_Selection () { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.Paste (); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = 20; - _textField.Cut (); - _textField.Paste (); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); + lock (Clipboard.Contents) { + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.Paste (); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = 20; + _textField.Cut (); + _textField.Paste (); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + } } [Fact] [InitShutdown] public void Copy_Or_Cut_And_Paste_With_No_Selection () { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = -1; - _textField.Paste (); - Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); - _textField.SelectedStart = 24; - _textField.Cut (); - Assert.Null (_textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = -1; - _textField.Paste (); - Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); + lock (Clipboard.Contents) { + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = -1; + _textField.Paste (); + Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); + _textField.SelectedStart = 24; + _textField.Cut (); + Assert.Null (_textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = -1; + _textField.Paste (); + Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); + } } [Fact] @@ -640,12 +644,14 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Paste_Always_Clear_The_SelectedText () { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - _textField.Paste (); - Assert.Null (_textField.SelectedText); + lock (Clipboard.Contents) { + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + _textField.Paste (); + Assert.Null (_textField.SelectedText); + } } [Fact] @@ -895,207 +901,209 @@ namespace Terminal.Gui.Views { [AutoInitShutdown] public void KeyBindings_Command () { - var tf = new TextField ("This is a test.") { Width = 20 }; - Assert.Equal (15, tf.Text.Length); - Assert.Equal (15, tf.CursorPosition); - Assert.False (tf.ReadOnly); + lock (Clipboard.Contents) { + var tf = new TextField ("This is a test.") { Width = 20 }; + Assert.Equal (15, tf.Text.Length); + Assert.Equal (15, tf.CursorPosition); + Assert.False (tf.ReadOnly); - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ("This is a test.", tf.Text); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - tf.ReadOnly = true; - Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - tf.ReadOnly = false; - tf.CursorPosition = 1; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - tf.CursorPosition = 5; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Null (tf.SelectedText); - tf.CursorPosition = 7; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("a", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is a", tf.SelectedText); - tf.CursorPosition = 3; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a test.", tf.SelectedText); - Assert.Equal (13, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Null (tf.SelectedText); - Assert.Equal (12, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (11, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (1, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (2, tf.CursorPosition); - tf.CursorPosition = 9; - tf.ReadOnly = true; - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - tf.ReadOnly = false; - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.AltMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (3, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (9, tf.CursorPosition); - Assert.True (tf.Used); - Assert.True (tf.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (9, tf.CursorPosition); - Assert.False (tf.Used); - tf.SelectedStart = 3; - tf.CursorPosition = 7; - Assert.Equal ("is a", tf.SelectedText); - Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.Equal (7, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); - Assert.Equal (" t", tf.Text); - Assert.Equal ("is is a", Clipboard.Contents); - tf.Text = "TAB to jump between text fields."; - Assert.Equal (0, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text fields.", tf.Text); - tf.CursorPosition = tf.Text.Length; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text ", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ("This is a test.", tf.Text); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + tf.ReadOnly = true; + Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + tf.ReadOnly = false; + tf.CursorPosition = 1; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + tf.CursorPosition = 5; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("s", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("s", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Null (tf.SelectedText); + tf.CursorPosition = 7; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("a", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is a", tf.SelectedText); + tf.CursorPosition = 3; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a test.", tf.SelectedText); + Assert.Equal (13, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Null (tf.SelectedText); + Assert.Equal (12, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (11, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (1, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (2, tf.CursorPosition); + tf.CursorPosition = 9; + tf.ReadOnly = true; + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + tf.ReadOnly = false; + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("est.", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.AltMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (8, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (6, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (3, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (6, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (8, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (9, tf.CursorPosition); + Assert.True (tf.Used); + Assert.True (tf.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (9, tf.CursorPosition); + Assert.False (tf.Used); + tf.SelectedStart = 3; + tf.CursorPosition = 7; + Assert.Equal ("is a", tf.SelectedText); + Assert.Equal ("est.", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.Equal (7, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); + Assert.Equal (" t", tf.Text); + Assert.Equal ("is is a", Clipboard.Contents); + tf.Text = "TAB to jump between text fields."; + Assert.Equal (0, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text fields.", tf.Text); + tf.CursorPosition = tf.Text.Length; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text ", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("", tf.Text); + } } [Fact] diff --git a/UnitTests/TextViewTests.cs b/UnitTests/TextViewTests.cs index 0b32588d3..14b123594 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -935,42 +935,44 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard () { - _textView.Text = "This is the first line.\nThis is the second line."; - var iteration = 0; - bool iterationsFinished = false; + lock (Clipboard.Contents) { + _textView.Text = "This is the first line.\nThis is the second line."; + var iteration = 0; + bool iterationsFinished = false; - while (!iterationsFinished) { - switch (iteration) { - case 0: - _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text); - Assert.Equal ("This is the first line.", Clipboard.Contents); - break; - case 1: - _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ("This is the second line.", _textView.Text); - Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents); - break; - case 2: - _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ("", _textView.Text); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", Clipboard.Contents); + while (!iterationsFinished) { + switch (iteration) { + case 0: + _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text); + Assert.Equal ("This is the first line.", Clipboard.Contents); + break; + case 1: + _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ("This is the second line.", _textView.Text); + Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents); + break; + case 2: + _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ("", _textView.Text); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", Clipboard.Contents); - // Paste - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.Text); - break; - default: - iterationsFinished = true; - break; + // Paste + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.Text); + break; + default: + iterationsFinished = true; + break; + } + iteration++; } - iteration++; } } @@ -1315,35 +1317,37 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Or_Cut_And_Paste_With_No_Selection () { - _textView.SelectionStartColumn = 20; - _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - Assert.Equal ("text", _textView.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.SelectionStartColumn = 0; - _textView.SelectionStartRow = 0; - Assert.Equal (new Point (24, 0), _textView.CursorPosition); - Assert.True (_textView.Selecting); - _textView.Selecting = false; - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); - _textView.SelectionStartColumn = 24; - _textView.SelectionStartRow = 0; - _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut - Assert.Equal (new Point (24, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("", _textView.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.SelectionStartColumn = 0; - _textView.SelectionStartRow = 0; - _textView.Selecting = false; - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); + lock (Clipboard.Contents) { + _textView.SelectionStartColumn = 20; + _textView.SelectionStartRow = 0; + _textView.CursorPosition = new Point (24, 0); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + Assert.Equal ("text", _textView.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textView.Text); + _textView.SelectionStartColumn = 0; + _textView.SelectionStartRow = 0; + Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.True (_textView.Selecting); + _textView.Selecting = false; + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); + _textView.SelectionStartColumn = 24; + _textView.SelectionStartRow = 0; + _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut + Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("", _textView.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textView.Text); + _textView.SelectionStartColumn = 0; + _textView.SelectionStartRow = 0; + _textView.Selecting = false; + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); + } } [Fact] @@ -1432,19 +1436,21 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Without_Selection () { - _textView.Text = "This is the first line.\nThis is the second line.\n"; - _textView.CursorPosition = new Point (0, _textView.Lines - 1); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - _textView.CursorPosition = new Point (3, 1); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - Assert.Equal (new Point (3, 2), _textView.CursorPosition); - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - Assert.Equal (new Point (3, 3), _textView.CursorPosition); + lock (Clipboard.Contents) { + _textView.Text = "This is the first line.\nThis is the second line.\n"; + _textView.CursorPosition = new Point (0, _textView.Lines - 1); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + _textView.CursorPosition = new Point (3, 1); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + Assert.Equal (new Point (3, 2), _textView.CursorPosition); + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + Assert.Equal (new Point (3, 3), _textView.CursorPosition); + } } [Fact] @@ -2424,448 +2430,450 @@ line. [AutoInitShutdown] public void KeyBindings_Command () { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { - Width = 10, - Height = 2, - Text = text - }; - var top = Application.Top; - top.Add (tv); - Application.Begin (top); + lock (Clipboard.Contents) { + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { + Width = 10, + Height = 2, + Text = text + }; + var top = Application.Top; + top.Add (tv); + Application.Begin (top); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (Point.Empty, tv.CursorPosition); - Assert.False (tv.ReadOnly); - Assert.True (tv.CanFocus); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (Point.Empty, tv.CursorPosition); + Assert.False (tv.ReadOnly); + Assert.True (tv.CanFocus); - tv.CanFocus = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - tv.CanFocus = true; - Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (2, tv.CurrentRow); - Assert.Equal (23, tv.CurrentColumn); - Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.NotNull (tv.Autocomplete); - Assert.Empty (tv.Autocomplete.AllSuggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+") - .Select (s => s.Value) - .Distinct ().ToList (); - Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count); - Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]); - Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]); - Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]); - Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]); - Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]); - Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]); - Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Single (tv.Autocomplete.Suggestions); - Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Single (tv.Autocomplete.Suggestions); - Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); - tv.Autocomplete.AllSuggestions = new List (); - tv.Autocomplete.ClearSuggestions (); - Assert.Empty (tv.Autocomplete.AllSuggestions); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (24, 1), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal (23, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length - Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length - Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (Point.Empty, tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (1, tv.SelectedLength); - Assert.Equal ("T", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); - Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (21, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); - Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (20, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - tv.CursorPosition = Point.Empty; - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - tv.ReadOnly = true; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - tv.ReadOnly = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (19, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (19, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - tv.SelectionStartColumn = 0; - Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (12, 2), tv.CursorPosition); - Assert.Equal (6, tv.SelectedLength); - Assert.Equal ("third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (8, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (12, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (6, tv.SelectedLength); - Assert.Equal ("third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.AllowsReturn); - tv.AllowsReturn = false; - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.False (tv.Selecting); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.False (tv.AllowsReturn); - tv.AllowsReturn = true; - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.AllowsReturn); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.Used); - Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); - Assert.False (tv.Used); - Assert.True (tv.AllowsTab); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - tv.AllowsTab = false; - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.False (tv.AllowsTab); - tv.AllowsTab = true; - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.True (tv.Selecting); - tv.Selecting = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); - Assert.True (tv.AllowsTab); - tv.AllowsTab = false; - Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); - Assert.False (tv.AllowsTab); - tv.AllowsTab = true; - Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.True (tv.AllowsTab); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ()))); + tv.CanFocus = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + tv.CanFocus = true; + Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (2, tv.CurrentRow); + Assert.Equal (23, tv.CurrentColumn); + Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.NotNull (tv.Autocomplete); + Assert.Empty (tv.Autocomplete.AllSuggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+") + .Select (s => s.Value) + .Distinct ().ToList (); + Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count); + Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]); + Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]); + Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]); + Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]); + Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]); + Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]); + Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Single (tv.Autocomplete.Suggestions); + Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Single (tv.Autocomplete.Suggestions); + Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); + tv.Autocomplete.AllSuggestions = new List (); + tv.Autocomplete.ClearSuggestions (); + Assert.Empty (tv.Autocomplete.AllSuggestions); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (24, 1), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal (23, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (28, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (28, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (Point.Empty, tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (1, tv.SelectedLength); + Assert.Equal ("T", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); + Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (21, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); + Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (20, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + tv.CursorPosition = Point.Empty; + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + tv.ReadOnly = true; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + tv.ReadOnly = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (19, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (19, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + tv.SelectionStartColumn = 0; + Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (6, tv.SelectedLength); + Assert.Equal ("third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (8, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (6, tv.SelectedLength); + Assert.Equal ("third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.AllowsReturn); + tv.AllowsReturn = false; + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.False (tv.Selecting); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.False (tv.AllowsReturn); + tv.AllowsReturn = true; + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.AllowsReturn); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.Used); + Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); + Assert.False (tv.Used); + Assert.True (tv.AllowsTab); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + tv.AllowsTab = false; + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.False (tv.AllowsTab); + tv.AllowsTab = true; + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.True (tv.Selecting); + tv.Selecting = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); + Assert.True (tv.AllowsTab); + tv.AllowsTab = false; + Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); + Assert.False (tv.AllowsTab); + tv.AllowsTab = true; + Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.True (tv.AllowsTab); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ()))); + } } [Fact] @@ -4574,37 +4582,39 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste () { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + lock (Clipboard.Contents) { + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (17, 0); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ("first", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ("first", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (11, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); + } } [Fact] @@ -4647,37 +4657,39 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter () { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + lock (Clipboard.Contents) { + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (18, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (18, 1), tv.CursorPosition); - tv.Selecting = false; - tv.CursorPosition = new Point (17, 1); + tv.Selecting = false; + tv.CursorPosition = new Point (17, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (4, tv.Lines); + Assert.Equal (new Point (18, 2), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 1), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (17, 1), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (4, tv.Lines); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + } } [Fact] @@ -4747,37 +4759,39 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste () { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + lock (Clipboard.Contents) { + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (17, 0); - Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (11, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); + } } [Fact] @@ -5116,61 +5130,63 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_KillToEndOfLine () { - var text = "First line.\nSecond line."; - var tv = new TextView () { Text = text }; + lock (Clipboard.Contents) { + var text = "First line.\nSecond line."; + var tv = new TextView () { Text = text }; - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ("First line.", Clipboard.Contents); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ("First line.", Clipboard.Contents); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + } } [Fact] From 1e70e08996a7d938f68317f0558fd9c4ed1a555e Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 18 Sep 2022 00:37:59 +0100 Subject: [PATCH 2/5] Contents must return the current value, no matter what value is. --- Terminal.Gui/Core/Clipboard/Clipboard.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Terminal.Gui/Core/Clipboard/Clipboard.cs b/Terminal.Gui/Core/Clipboard/Clipboard.cs index 910470a86..914dd0153 100644 --- a/Terminal.Gui/Core/Clipboard/Clipboard.cs +++ b/Terminal.Gui/Core/Clipboard/Clipboard.cs @@ -15,11 +15,7 @@ namespace Terminal.Gui { get { try { if (IsSupported) { - var clip = ustring.Make (Application.Driver.Clipboard.GetClipboardData ()); - if (clip != null) { - return contents = clip; - } - return clip; + return contents = ustring.Make (Application.Driver.Clipboard.GetClipboardData ()); } else { return contents; } From e821435bacc9f945980db8eedf887ca38cb0f22f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 18 Sep 2022 01:03:20 +0100 Subject: [PATCH 3/5] Including also the variables inside the lock. --- UnitTests/ClipboardTests.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/UnitTests/ClipboardTests.cs b/UnitTests/ClipboardTests.cs index cb2287aaa..3ba25a0ad 100644 --- a/UnitTests/ClipboardTests.cs +++ b/UnitTests/ClipboardTests.cs @@ -79,11 +79,12 @@ namespace Terminal.Gui.Core { [AutoInitShutdown] public void Contents_Gets_From_OS_Clipboard () { - var clipText = "This is a clipboard unit test to get clipboard from OS."; - var exit = false; - var getClipText = ""; - lock (Clipboard.Contents) { + + var clipText = "This is a clipboard unit test to get clipboard from OS."; + var exit = false; + var getClipText = ""; + Application.Iteration += () => { if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { // using (Process clipExe = new Process { @@ -188,12 +189,12 @@ namespace Terminal.Gui.Core { Application.RequestStop (); }; - } - Application.Run (); + Application.Run (); - if (!exit) { - Assert.Equal (clipText, getClipText); + if (!exit) { + Assert.Equal (clipText, getClipText); + } } } From 17b98ad2940cfdabb1648a9bda885393bc362f63 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 18 Sep 2022 01:26:52 +0100 Subject: [PATCH 4/5] lock cannot have a null argument and sometime the Clipboard.Contents is null. --- UnitTests/ClipboardTests.cs | 237 ++++--- UnitTests/TextFieldTests.cs | 472 +++++++------ UnitTests/TextViewTests.cs | 1288 +++++++++++++++++------------------ 3 files changed, 983 insertions(+), 1014 deletions(-) diff --git a/UnitTests/ClipboardTests.cs b/UnitTests/ClipboardTests.cs index 3ba25a0ad..25c59d180 100644 --- a/UnitTests/ClipboardTests.cs +++ b/UnitTests/ClipboardTests.cs @@ -8,16 +8,14 @@ namespace Terminal.Gui.Core { [AutoInitShutdown] public void Contents_Gets_Sets () { - lock (Clipboard.Contents) { - var clipText = "This is a clipboard unit test."; - Clipboard.Contents = clipText; + var clipText = "This is a clipboard unit test."; + Clipboard.Contents = clipText; - Application.Iteration += () => Application.RequestStop (); + Application.Iteration += () => Application.RequestStop (); - Application.Run (); + Application.Run (); - Assert.Equal (clipText, Clipboard.Contents); - } + Assert.Equal (clipText, Clipboard.Contents); } [Fact] @@ -55,23 +53,21 @@ namespace Terminal.Gui.Core { [AutoInitShutdown] public void TrySetClipboardData_Sets_The_OS_Clipboard () { - lock (Clipboard.Contents) { - var clipText = "Trying to set the OS clipboard."; - if (Clipboard.IsSupported) { - Assert.True (Clipboard.TrySetClipboardData (clipText)); - } else { - Assert.False (Clipboard.TrySetClipboardData (clipText)); - } + var clipText = "Trying to set the OS clipboard."; + if (Clipboard.IsSupported) { + Assert.True (Clipboard.TrySetClipboardData (clipText)); + } else { + Assert.False (Clipboard.TrySetClipboardData (clipText)); + } - Application.Iteration += () => Application.RequestStop (); + Application.Iteration += () => Application.RequestStop (); - Application.Run (); + Application.Run (); - if (Clipboard.IsSupported) { - Assert.Equal (clipText, Clipboard.Contents); - } else { - Assert.NotEqual (clipText, Clipboard.Contents); - } + if (Clipboard.IsSupported) { + Assert.Equal (clipText, Clipboard.Contents); + } else { + Assert.NotEqual (clipText, Clipboard.Contents); } } @@ -79,122 +75,119 @@ namespace Terminal.Gui.Core { [AutoInitShutdown] public void Contents_Gets_From_OS_Clipboard () { - lock (Clipboard.Contents) { + var clipText = "This is a clipboard unit test to get clipboard from OS."; + var exit = false; + var getClipText = ""; - var clipText = "This is a clipboard unit test to get clipboard from OS."; - var exit = false; - var getClipText = ""; + Application.Iteration += () => { + if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { + // using (Process clipExe = new Process { + // StartInfo = new ProcessStartInfo { + // RedirectStandardInput = true, + // FileName = "clip" + // } + // }) { + // clipExe.Start (); + // clipExe.StandardInput.Write (clipText); + // clipExe.StandardInput.Close (); + // var result = clipExe.WaitForExit (500); + // if (result) { + // clipExe.WaitForExit (); + // } + // } - Application.Iteration += () => { - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - // using (Process clipExe = new Process { - // StartInfo = new ProcessStartInfo { - // RedirectStandardInput = true, - // FileName = "clip" - // } - // }) { - // clipExe.Start (); - // clipExe.StandardInput.Write (clipText); - // clipExe.StandardInput.Close (); - // var result = clipExe.WaitForExit (500); - // if (result) { - // clipExe.WaitForExit (); - // } - // } - - using (Process pwsh = new Process { - StartInfo = new ProcessStartInfo { - FileName = "powershell", - Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\"" - } - }) { - pwsh.Start (); - pwsh.WaitForExit (); + using (Process pwsh = new Process { + StartInfo = new ProcessStartInfo { + FileName = "powershell", + Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\"" } - getClipText = Clipboard.Contents.ToString (); + }) { + pwsh.Start (); + pwsh.WaitForExit (); + } + getClipText = Clipboard.Contents.ToString (); - } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) { - using (Process copy = new Process { - StartInfo = new ProcessStartInfo { - RedirectStandardInput = true, - FileName = "pbcopy" - } - }) { - copy.Start (); - copy.StandardInput.Write (clipText); - copy.StandardInput.Close (); - copy.WaitForExit (); + } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) { + using (Process copy = new Process { + StartInfo = new ProcessStartInfo { + RedirectStandardInput = true, + FileName = "pbcopy" } - getClipText = Clipboard.Contents.ToString (); + }) { + copy.Start (); + copy.StandardInput.Write (clipText); + copy.StandardInput.Close (); + copy.WaitForExit (); + } + getClipText = Clipboard.Contents.ToString (); - } else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) { - if (Is_WSL_Platform ()) { - try { - using (Process bash = new Process { - StartInfo = new ProcessStartInfo { - FileName = "powershell.exe", - Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\"" - } - }) { - bash.Start (); - bash.WaitForExit (); + } else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) { + if (Is_WSL_Platform ()) { + try { + using (Process bash = new Process { + StartInfo = new ProcessStartInfo { + FileName = "powershell.exe", + Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\"" } + }) { + bash.Start (); + bash.WaitForExit (); + } - //using (Process clipExe = new Process { - // StartInfo = new ProcessStartInfo { - // RedirectStandardInput = true, - // FileName = "clip.exe" - // } - //}) { - // clipExe.Start (); - // clipExe.StandardInput.Write (clipText); - // clipExe.StandardInput.Close (); - // clipExe.WaitForExit (); - // //var result = clipExe.WaitForExit (500); - // //if (result) { - // // clipExe.WaitForExit (); - // //} - //} - } catch { - exit = true; - } - if (!exit) { - getClipText = Clipboard.Contents.ToString (); - } - Application.RequestStop (); - return; - } - if (exit = xclipExists () == false) { - // xclip doesn't exist then exit. - Application.RequestStop (); - return; - } - - using (Process bash = new Process { - StartInfo = new ProcessStartInfo { - FileName = "bash", - Arguments = $"-c \"xclip -sel clip -i\"", - RedirectStandardInput = true, - } - }) { - bash.Start (); - bash.StandardInput.Write (clipText); - bash.StandardInput.Close (); - bash.WaitForExit (); + //using (Process clipExe = new Process { + // StartInfo = new ProcessStartInfo { + // RedirectStandardInput = true, + // FileName = "clip.exe" + // } + //}) { + // clipExe.Start (); + // clipExe.StandardInput.Write (clipText); + // clipExe.StandardInput.Close (); + // clipExe.WaitForExit (); + // //var result = clipExe.WaitForExit (500); + // //if (result) { + // // clipExe.WaitForExit (); + // //} + //} + } catch { + exit = true; } if (!exit) { getClipText = Clipboard.Contents.ToString (); } + Application.RequestStop (); + return; + } + if (exit = xclipExists () == false) { + // xclip doesn't exist then exit. + Application.RequestStop (); + return; } - Application.RequestStop (); - }; - - Application.Run (); - - if (!exit) { - Assert.Equal (clipText, getClipText); + using (Process bash = new Process { + StartInfo = new ProcessStartInfo { + FileName = "bash", + Arguments = $"-c \"xclip -sel clip -i\"", + RedirectStandardInput = true, + } + }) { + bash.Start (); + bash.StandardInput.Write (clipText); + bash.StandardInput.Close (); + bash.WaitForExit (); + } + if (!exit) { + getClipText = Clipboard.Contents.ToString (); + } } + + Application.RequestStop (); + }; + + Application.Run (); + + if (!exit) { + Assert.Equal (clipText, getClipText); } } diff --git a/UnitTests/TextFieldTests.cs b/UnitTests/TextFieldTests.cs index 6d38fef32..3fcd92f44 100644 --- a/UnitTests/TextFieldTests.cs +++ b/UnitTests/TextFieldTests.cs @@ -584,42 +584,38 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Or_Cut_And_Paste_With_Selection () { - lock (Clipboard.Contents) { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.Paste (); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = 20; - _textField.Cut (); - _textField.Paste (); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - } + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.Paste (); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = 20; + _textField.Cut (); + _textField.Paste (); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); } [Fact] [InitShutdown] public void Copy_Or_Cut_And_Paste_With_No_Selection () { - lock (Clipboard.Contents) { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = -1; - _textField.Paste (); - Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); - _textField.SelectedStart = 24; - _textField.Cut (); - Assert.Null (_textField.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textField.Text); - _textField.SelectedStart = -1; - _textField.Paste (); - Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); - } + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = -1; + _textField.Paste (); + Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); + _textField.SelectedStart = 24; + _textField.Cut (); + Assert.Null (_textField.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textField.Text); + _textField.SelectedStart = -1; + _textField.Paste (); + Assert.Equal ("TAB to jump between texttext fields.", _textField.Text); } [Fact] @@ -644,14 +640,12 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Paste_Always_Clear_The_SelectedText () { - lock (Clipboard.Contents) { - _textField.SelectedStart = 20; - _textField.CursorPosition = 24; - _textField.Copy (); - Assert.Equal ("text", _textField.SelectedText); - _textField.Paste (); - Assert.Null (_textField.SelectedText); - } + _textField.SelectedStart = 20; + _textField.CursorPosition = 24; + _textField.Copy (); + Assert.Equal ("text", _textField.SelectedText); + _textField.Paste (); + Assert.Null (_textField.SelectedText); } [Fact] @@ -901,209 +895,207 @@ namespace Terminal.Gui.Views { [AutoInitShutdown] public void KeyBindings_Command () { - lock (Clipboard.Contents) { - var tf = new TextField ("This is a test.") { Width = 20 }; - Assert.Equal (15, tf.Text.Length); - Assert.Equal (15, tf.CursorPosition); - Assert.False (tf.ReadOnly); + var tf = new TextField ("This is a test.") { Width = 20 }; + Assert.Equal (15, tf.Text.Length); + Assert.Equal (15, tf.CursorPosition); + Assert.False (tf.ReadOnly); - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ("This is a test.", tf.Text); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - tf.ReadOnly = true; - Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); - Assert.Equal ("his is a test.", tf.Text); - tf.ReadOnly = false; - tf.CursorPosition = 1; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - tf.CursorPosition = 5; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (" a test.", tf.SelectedText); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (0, tf.CursorPosition); - tf.CursorPosition = 5; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("s", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Null (tf.SelectedText); - tf.CursorPosition = 7; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("a", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is is a", tf.SelectedText); - tf.CursorPosition = 3; - tf.SelectedStart = -1; - Assert.Null (tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal ("is a test.", tf.SelectedText); - Assert.Equal (13, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Null (tf.SelectedText); - Assert.Equal (12, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (11, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (13, tf.CursorPosition); - tf.CursorPosition = 0; - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (1, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.Equal (2, tf.CursorPosition); - tf.CursorPosition = 9; - tf.ReadOnly = true; - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - tf.ReadOnly = false; - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.AltMask, new KeyModifiers ()))); - Assert.Equal ("is is a test.", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (3, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (6, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (8, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (9, tf.CursorPosition); - Assert.True (tf.Used); - Assert.True (tf.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal (9, tf.CursorPosition); - Assert.False (tf.Used); - tf.SelectedStart = 3; - tf.CursorPosition = 7; - Assert.Equal ("is a", tf.SelectedText); - Assert.Equal ("est.", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.True (tf.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("is is a t", tf.Text); - Assert.Equal ("is a", Clipboard.Contents); - Assert.Equal (7, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); - Assert.Equal (" t", tf.Text); - Assert.Equal ("is is a", Clipboard.Contents); - tf.Text = "TAB to jump between text fields."; - Assert.Equal (0, tf.CursorPosition); - Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text fields.", tf.Text); - tf.CursorPosition = tf.Text.Length; - Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text ", tf.Text); - Assert.True (tf.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("to jump between text ", tf.SelectedText); - Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ("", tf.Text); - } + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ("This is a test.", tf.Text); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + tf.ReadOnly = true; + Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); + Assert.Equal ("his is a test.", tf.Text); + tf.ReadOnly = false; + tf.CursorPosition = 1; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + tf.CursorPosition = 5; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (" a test.", tf.SelectedText); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (0, tf.CursorPosition); + tf.CursorPosition = 5; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("s", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("s", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Null (tf.SelectedText); + tf.CursorPosition = 7; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("a", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is is a", tf.SelectedText); + tf.CursorPosition = 3; + tf.SelectedStart = -1; + Assert.Null (tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.ShiftMask | Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal ("is a test.", tf.SelectedText); + Assert.Equal (13, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Null (tf.SelectedText); + Assert.Equal (12, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (11, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (13, tf.CursorPosition); + tf.CursorPosition = 0; + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (1, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.Equal (2, tf.CursorPosition); + tf.CursorPosition = 9; + tf.ReadOnly = true; + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + tf.ReadOnly = false; + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("est.", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.AltMask, new KeyModifiers ()))); + Assert.Equal ("is is a test.", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (8, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (6, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (3, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (6, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (8, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (9, tf.CursorPosition); + Assert.True (tf.Used); + Assert.True (tf.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal (9, tf.CursorPosition); + Assert.False (tf.Used); + tf.SelectedStart = 3; + tf.CursorPosition = 7; + Assert.Equal ("is a", tf.SelectedText); + Assert.Equal ("est.", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.True (tf.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("is is a t", tf.Text); + Assert.Equal ("is a", Clipboard.Contents); + Assert.Equal (7, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); + Assert.Equal (" t", tf.Text); + Assert.Equal ("is is a", Clipboard.Contents); + tf.Text = "TAB to jump between text fields."; + Assert.Equal (0, tf.CursorPosition); + Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text fields.", tf.Text); + tf.CursorPosition = tf.Text.Length; + Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text ", tf.Text); + Assert.True (tf.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("to jump between text ", tf.SelectedText); + Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ("", tf.Text); } [Fact] diff --git a/UnitTests/TextViewTests.cs b/UnitTests/TextViewTests.cs index 14b123594..0b32588d3 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -935,44 +935,42 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard () { - lock (Clipboard.Contents) { - _textView.Text = "This is the first line.\nThis is the second line."; - var iteration = 0; - bool iterationsFinished = false; + _textView.Text = "This is the first line.\nThis is the second line."; + var iteration = 0; + bool iterationsFinished = false; - while (!iterationsFinished) { - switch (iteration) { - case 0: - _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text); - Assert.Equal ("This is the first line.", Clipboard.Contents); - break; - case 1: - _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ("This is the second line.", _textView.Text); - Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents); - break; - case 2: - _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal (0, _textView.CursorPosition.X); - Assert.Equal (0, _textView.CursorPosition.Y); - Assert.Equal ("", _textView.Text); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", Clipboard.Contents); + while (!iterationsFinished) { + switch (iteration) { + case 0: + _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ($"{Environment.NewLine}This is the second line.", _textView.Text); + Assert.Equal ("This is the first line.", Clipboard.Contents); + break; + case 1: + _textView.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ("This is the second line.", _textView.Text); + Assert.Equal ($"This is the first line.{Environment.NewLine}", Clipboard.Contents); + break; + case 2: + _textView.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal (0, _textView.CursorPosition.X); + Assert.Equal (0, _textView.CursorPosition.Y); + Assert.Equal ("", _textView.Text); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", Clipboard.Contents); - // Paste - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.Text); - break; - default: - iterationsFinished = true; - break; - } - iteration++; + // Paste + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", _textView.Text); + break; + default: + iterationsFinished = true; + break; } + iteration++; } } @@ -1317,37 +1315,35 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Or_Cut_And_Paste_With_No_Selection () { - lock (Clipboard.Contents) { - _textView.SelectionStartColumn = 20; - _textView.SelectionStartRow = 0; - _textView.CursorPosition = new Point (24, 0); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - Assert.Equal ("text", _textView.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.SelectionStartColumn = 0; - _textView.SelectionStartRow = 0; - Assert.Equal (new Point (24, 0), _textView.CursorPosition); - Assert.True (_textView.Selecting); - _textView.Selecting = false; - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); - _textView.SelectionStartColumn = 24; - _textView.SelectionStartRow = 0; - _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut - Assert.Equal (new Point (24, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("", _textView.SelectedText); - Assert.Equal ("TAB to jump between text fields.", _textView.Text); - _textView.SelectionStartColumn = 0; - _textView.SelectionStartRow = 0; - _textView.Selecting = false; - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal (new Point (28, 0), _textView.CursorPosition); - Assert.False (_textView.Selecting); - Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); - } + _textView.SelectionStartColumn = 20; + _textView.SelectionStartRow = 0; + _textView.CursorPosition = new Point (24, 0); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + Assert.Equal ("text", _textView.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textView.Text); + _textView.SelectionStartColumn = 0; + _textView.SelectionStartRow = 0; + Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.True (_textView.Selecting); + _textView.Selecting = false; + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); + _textView.SelectionStartColumn = 24; + _textView.SelectionStartRow = 0; + _textView.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ())); // Cut + Assert.Equal (new Point (24, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("", _textView.SelectedText); + Assert.Equal ("TAB to jump between text fields.", _textView.Text); + _textView.SelectionStartColumn = 0; + _textView.SelectionStartRow = 0; + _textView.Selecting = false; + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal (new Point (28, 0), _textView.CursorPosition); + Assert.False (_textView.Selecting); + Assert.Equal ("TAB to jump between texttext fields.", _textView.Text); } [Fact] @@ -1436,21 +1432,19 @@ namespace Terminal.Gui.Views { [InitShutdown] public void Copy_Without_Selection () { - lock (Clipboard.Contents) { - _textView.Text = "This is the first line.\nThis is the second line.\n"; - _textView.CursorPosition = new Point (0, _textView.Lines - 1); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - _textView.CursorPosition = new Point (3, 1); - _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - Assert.Equal (new Point (3, 2), _textView.CursorPosition); - _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); - Assert.Equal (new Point (3, 3), _textView.CursorPosition); - } + _textView.Text = "This is the first line.\nThis is the second line.\n"; + _textView.CursorPosition = new Point (0, _textView.Lines - 1); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + _textView.CursorPosition = new Point (3, 1); + _textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())); // Copy + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + Assert.Equal (new Point (3, 2), _textView.CursorPosition); + _textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())); // Paste + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the second line.{Environment.NewLine}{Environment.NewLine}", _textView.Text); + Assert.Equal (new Point (3, 3), _textView.CursorPosition); } [Fact] @@ -2430,450 +2424,448 @@ line. [AutoInitShutdown] public void KeyBindings_Command () { - lock (Clipboard.Contents) { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { - Width = 10, - Height = 2, - Text = text - }; - var top = Application.Top; - top.Add (tv); - Application.Begin (top); + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { + Width = 10, + Height = 2, + Text = text + }; + var top = Application.Top; + top.Add (tv); + Application.Begin (top); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (Point.Empty, tv.CursorPosition); - Assert.False (tv.ReadOnly); - Assert.True (tv.CanFocus); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (Point.Empty, tv.CursorPosition); + Assert.False (tv.ReadOnly); + Assert.True (tv.CanFocus); - tv.CanFocus = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - tv.CanFocus = true; - Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (2, tv.CurrentRow); - Assert.Equal (23, tv.CurrentColumn); - Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.NotNull (tv.Autocomplete); - Assert.Empty (tv.Autocomplete.AllSuggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (new Point (23, 2), tv.CursorPosition); - tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+") - .Select (s => s.Value) - .Distinct ().ToList (); - Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count); - Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]); - Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]); - Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]); - Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]); - Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]); - Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]); - Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); - tv.Redraw (tv.Bounds); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); - Assert.Equal (new Point (24, 2), tv.CursorPosition); - Assert.Single (tv.Autocomplete.Suggestions); - Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Single (tv.Autocomplete.Suggestions); - Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); - tv.Autocomplete.AllSuggestions = new List (); - tv.Autocomplete.ClearSuggestions (); - Assert.Empty (tv.Autocomplete.AllSuggestions); - Assert.Empty (tv.Autocomplete.Suggestions); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (24, 1), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal (23, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length - Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (24, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length - Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (28, tv.GetCurrentLine ().Count); - Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (Point.Empty, tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (1, 0), tv.CursorPosition); - Assert.Equal (1, tv.SelectedLength); - Assert.Equal ("T", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); - Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); - Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (21, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); - Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (20, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - tv.CursorPosition = Point.Empty; - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - tv.ReadOnly = true; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - tv.ReadOnly = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (19, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (19, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - tv.SelectionStartColumn = 0; - Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (19, 0), tv.CursorPosition); - Assert.Equal (19, tv.SelectedLength); - Assert.Equal ("is is the first lin", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("is is the first lin", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.Equal (0, tv.SelectionStartColumn); - Assert.Equal (0, tv.SelectionStartRow); - Assert.Equal ("", Clipboard.Contents); - Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (12, 2), tv.CursorPosition); - Assert.Equal (6, tv.SelectedLength); - Assert.Equal ("third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (8, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (12, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (6, tv.SelectedLength); - Assert.Equal ("third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 2), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (28, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.AllowsReturn); - tv.AllowsReturn = false; - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.False (tv.Selecting); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.False (tv.AllowsReturn); - tv.AllowsReturn = true; - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 1), tv.CursorPosition); - Assert.Equal (0, tv.SelectedLength); - Assert.Equal ("", tv.SelectedText); - Assert.False (tv.Selecting); - Assert.True (tv.AllowsReturn); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); - Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); - Assert.True (tv.Selecting); - Assert.True (tv.Used); - Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); - Assert.False (tv.Used); - Assert.True (tv.AllowsTab); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - tv.AllowsTab = false; - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.False (tv.AllowsTab); - tv.AllowsTab = true; - Assert.Equal (new Point (18, 2), tv.CursorPosition); - Assert.True (tv.Selecting); - tv.Selecting = false; - Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); - Assert.True (tv.AllowsTab); - tv.AllowsTab = false; - Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); - Assert.False (tv.AllowsTab); - tv.AllowsTab = true; - Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.True (tv.AllowsTab); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); - Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ()))); - } + tv.CanFocus = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + tv.CanFocus = true; + Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (2, tv.CurrentRow); + Assert.Equal (23, tv.CurrentColumn); + Assert.Equal (tv.CurrentColumn, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.False (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.NotNull (tv.Autocomplete); + Assert.Empty (tv.Autocomplete.AllSuggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (new Point (23, 2), tv.CursorPosition); + tv.Autocomplete.AllSuggestions = Regex.Matches (tv.Text.ToString (), "\\w+") + .Select (s => s.Value) + .Distinct ().ToList (); + Assert.Equal (7, tv.Autocomplete.AllSuggestions.Count); + Assert.Equal ("This", tv.Autocomplete.AllSuggestions [0]); + Assert.Equal ("is", tv.Autocomplete.AllSuggestions [1]); + Assert.Equal ("the", tv.Autocomplete.AllSuggestions [2]); + Assert.Equal ("first", tv.Autocomplete.AllSuggestions [3]); + Assert.Equal ("line", tv.Autocomplete.AllSuggestions [4]); + Assert.Equal ("second", tv.Autocomplete.AllSuggestions [5]); + Assert.Equal ("third", tv.Autocomplete.AllSuggestions [^1]); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F, new KeyModifiers ()))); + tv.Redraw (tv.Bounds); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.F", tv.Text); + Assert.Equal (new Point (24, 2), tv.CursorPosition); + Assert.Single (tv.Autocomplete.Suggestions); + Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Single (tv.Autocomplete.Suggestions); + Assert.Equal ("first", tv.Autocomplete.Suggestions [0]); + tv.Autocomplete.AllSuggestions = new List (); + tv.Autocomplete.ClearSuggestions (); + Assert.Empty (tv.Autocomplete.AllSuggestions); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (24, 1), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (((int)'V' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal (23, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.True (tv.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (28, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (24, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 1), tv.CursorPosition); // gets the previous length + Assert.Equal (24 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($".{Environment.NewLine}This is the third line.", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.PageDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (28, tv.GetCurrentLine ().Count); + Assert.Equal (new Point (23, 2), tv.CursorPosition); // gets the previous length + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (Point.Empty, tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.N | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.P | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (1, 0), tv.CursorPosition); + Assert.Equal (1, tv.SelectedLength); + Assert.Equal ("T", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ()))); + Assert.Equal ($"his is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); + Assert.Equal ($"is is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (21, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ()))); + Assert.Equal ($"is is the first line{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (20, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + tv.CursorPosition = Point.Empty; + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + tv.ReadOnly = true; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + tv.ReadOnly = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (19, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Space | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (19, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + tv.SelectionStartColumn = 0; + Assert.True (tv.ProcessKey (new KeyEvent (((int)'C' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"is is the first lin{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (19, 0), tv.CursorPosition); + Assert.Equal (19, tv.SelectedLength); + Assert.Equal ("is is the first lin", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.True (tv.ProcessKey (new KeyEvent (((int)'W' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("is is the first lin", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.Equal (0, tv.SelectionStartColumn); + Assert.Equal (0, tv.SelectionStartRow); + Assert.Equal ("", Clipboard.Contents); + Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorLeft | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (6, tv.SelectedLength); + Assert.Equal ("third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (8, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (12, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (6, tv.SelectedLength); + Assert.Equal ("third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 2), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); + Assert.Equal (new Point (28, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.False (tv.Selecting); Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.AllowsReturn); + tv.AllowsReturn = false; + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.False (tv.Selecting); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.False (tv.AllowsReturn); + tv.AllowsReturn = true; + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 1), tv.CursorPosition); + Assert.Equal (0, tv.SelectedLength); + Assert.Equal ("", tv.SelectedText); + Assert.False (tv.Selecting); + Assert.True (tv.AllowsReturn); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (42 + Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); + Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.ProcessKey (new KeyEvent (Key.T | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.Equal (42 + Environment.NewLine.Length * 2, tv.SelectedLength); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.SelectedText); + Assert.True (tv.Selecting); + Assert.True (tv.Used); + Assert.True (tv.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ()))); + Assert.False (tv.Used); + Assert.True (tv.AllowsTab); + Assert.Equal (new Point (18, 2), tv.CursorPosition); + tv.AllowsTab = false; + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.False (tv.AllowsTab); + tv.AllowsTab = true; + Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.True (tv.Selecting); + tv.Selecting = false; + Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); + Assert.True (tv.AllowsTab); + tv.AllowsTab = false; + Assert.False (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third \t", tv.Text); + Assert.False (tv.AllowsTab); + tv.AllowsTab = true; + Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text); + Assert.True (tv.AllowsTab); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()))); + Assert.False (tv.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ()))); } [Fact] @@ -4582,39 +4574,37 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Simple_Copy_Multi_Line_Selected_Paste () { - lock (Clipboard.Contents) { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (17, 0); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ("first", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ("first", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (11, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); - } + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); } [Fact] @@ -4657,39 +4647,37 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Multi_Line_Selected_Copy_Simple_Paste_Starting_On_Letter () { - lock (Clipboard.Contents) { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (18, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (18, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (18, 1), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ($"first line.{Environment.NewLine}This is the second", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (18, 1), tv.CursorPosition); - tv.Selecting = false; - tv.CursorPosition = new Point (17, 1); + tv.Selecting = false; + tv.CursorPosition = new Point (17, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (4, tv.Lines); + Assert.Equal (new Point (18, 2), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (17, 1), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (17, 1), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (4, tv.Lines); - Assert.Equal (new Point (18, 2), tv.CursorPosition); - } + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first line.{Environment.NewLine}This is the seconfirst line.{Environment.NewLine}This is the secondd line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (4, tv.Lines); + Assert.Equal (new Point (18, 2), tv.CursorPosition); } [Fact] @@ -4759,39 +4747,37 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_Cut_Multi_Line_Selected_Paste () { - lock (Clipboard.Contents) { - var text = "This is the first line.\nThis is the second line.\nThis is the third line."; - var tv = new TextView () { Text = text }; + var text = "This is the first line.\nThis is the second line.\nThis is the third line."; + var tv = new TextView () { Text = text }; - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (17, 0); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (17, 0); - Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.W | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - tv.SelectionStartColumn = 12; - tv.CursorPosition = new Point (11, 1); + tv.SelectionStartColumn = 12; + tv.CursorPosition = new Point (11, 1); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (12, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the line.{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (3, tv.Lines); + Assert.Equal (new Point (12, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (17, 0), tv.CursorPosition); - } + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"This is the first second line.{Environment.NewLine}This is the third line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (17, 0), tv.CursorPosition); } [Fact] @@ -5130,63 +5116,61 @@ line. [AutoInitShutdown] public void HistoryText_Undo_Redo_KillToEndOfLine () { - lock (Clipboard.Contents) { - var text = "First line.\nSecond line."; - var tv = new TextView () { Text = text }; + var text = "First line.\nSecond line."; + var tv = new TextView () { Text = text }; - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ("First line.", Clipboard.Contents); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ("First line.", Clipboard.Contents); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("", tv.Text); - Assert.Equal ("", tv.SelectedText); - Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("", tv.Text); + Assert.Equal ("", tv.SelectedText); + Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - // Undo - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + // Undo + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - // Redo - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); - Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + // Redo + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); + Assert.Equal (2, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("Second line.", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("Second line.", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); - Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); - Assert.Equal ("", tv.Text); - Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); - } + Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ()))); + Assert.Equal ("", tv.Text); + Assert.Equal (1, tv.Lines); + Assert.Equal (new Point (0, 0), tv.CursorPosition); } [Fact] From d5425485955410ff17f0201bda7ee7b2cb819124 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 18 Sep 2022 02:16:11 +0100 Subject: [PATCH 5/5] Incremented the sleep timeout. --- UnitTests/ApplicationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/ApplicationTests.cs b/UnitTests/ApplicationTests.cs index 8c335da05..56fdb9223 100644 --- a/UnitTests/ApplicationTests.cs +++ b/UnitTests/ApplicationTests.cs @@ -1318,7 +1318,7 @@ namespace Terminal.Gui.Core { if (myi == 0) { // let the timeouts run for a bit - Thread.Sleep (5000); + Thread.Sleep (10000); // then tell the application to quit Application.MainLoop.Invoke (() => Application.RequestStop ());