Browse Source

Merge branch 'develop' into splitcontainer

Tig 2 years ago
parent
commit
2203d87baf
4 changed files with 28 additions and 2 deletions
  1. 0 1
      README.md
  2. 0 1
      Terminal.Gui/README.md
  3. 1 0
      Terminal.Gui/Views/TextField.cs
  4. 27 0
      UnitTests/TextFieldTests.cs

+ 0 - 1
README.md

@@ -12,7 +12,6 @@ A toolkit for building rich console apps for .NET, .NET Core, and Mono that work
 
 ![Sample app](docfx/images/sample.gif)
 
-
 ## Quick Start
 
 Paste these commands into your favorite terminal on Windows, Mac, or Linux. This will install the [Terminal.Gui.Templates](https://github.com/gui-cs/Terminal.Gui.templates), create a new "Hello World" TUI app, and run it.

+ 0 - 1
Terminal.Gui/README.md

@@ -68,7 +68,6 @@ The PR title should be of the form "Release v2.3.4"
 git checkout develop
 git pull upstream develop
 git checkout -b v_2_3_4
-git merge develop
 git add .
 git commit -m "Release v2.3.4"
 git push

+ 1 - 0
Terminal.Gui/Views/TextField.cs

@@ -298,6 +298,7 @@ namespace Terminal.Gui {
 					}
 					return;
 				}
+				ClearAllSelection ();
 				text = TextModel.ToRunes (newText.NewText);
 
 				if (!Secret && !historyText.IsFromHistory) {

+ 27 - 0
UnitTests/TextFieldTests.cs

@@ -1296,5 +1296,32 @@ namespace Terminal.Gui.Views {
 			Assert.Equal ($"{text}A", tf.Text);
 			Assert.True (tf.IsDirty);
 		}
+
+		[InlineData ("a")] // Lower than selection
+		[InlineData ("aaaaaaaaaaa")] // Greater than selection
+		[InlineData ("aaaa")] // Equal than selection
+		[Theory]
+		public void TestSetTextAndMoveCursorToEnd_WhenExistingSelection (string newText)
+		{
+			var tf = new TextField ();
+			tf.Text = "fish";
+			tf.CursorPosition = tf.Text.Length;
+
+			tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));
+
+			tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
+			tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
+
+			Assert.Equal (1, tf.CursorPosition);
+			Assert.Equal (2, tf.SelectedLength);
+			Assert.Equal ("is", tf.SelectedText);
+
+			tf.Text = newText;
+			tf.CursorPosition = tf.Text.Length;
+
+			Assert.Equal (newText.Length, tf.CursorPosition);
+			Assert.Equal (0, tf.SelectedLength);
+			Assert.Null (tf.SelectedText);
+		}
 	}
 }