浏览代码

Fixes #2047. Tests are failing locally after merging #2046

BDisp 2 年之前
父节点
当前提交
c350886b5d

+ 5 - 1
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;
 					}

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -2722,7 +2722,7 @@ namespace Terminal.Gui {
 		/// <returns>The text formatter size more the <see cref="TextFormatter.HotKeySpecifier"/> length.</returns>
 		public Size GetBoundsTextFormatterSize ()
 		{
-			if (TextFormatter.Text == null)
+			if (ustring.IsNullOrEmpty (TextFormatter.Text))
 				return Bounds.Size;
 
 			return new Size (frame.Size.Width + GetHotKeySpecifierLength (),

+ 2 - 2
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 {
 		/// </summary>
 		public virtual void Paste ()
 		{
-			if (ReadOnly || Clipboard.Contents == null) {
+			if (ReadOnly || ustring.IsNullOrEmpty (Clipboard.Contents)) {
 				return;
 			}
 

+ 7 - 5
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]

+ 241 - 233
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);
-
-			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);
+			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);
+			}
 		}
 
 		[Fact]

文件差异内容过多而无法显示
+ 527 - 519
UnitTests/TextViewTests.cs


部分文件因为文件数量过多而无法显示