Explorar o código

Fixes #2196. TextView: Setting Text places cursor at beginning, unlike TextField (#2572)

* Fixes #2196. TextView: Setting Text places cursor at beginning, unlike TextField

* Change all private members to have the _prefix.

* Renamed local member to prevLayoutStyle.

* Helper function for SetNeedsDisplay.
BDisp %!s(int64=2) %!d(string=hai) anos
pai
achega
be67e0f09f

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 233 - 228
Terminal.Gui/Views/TextView.cs


+ 17 - 7
UICatalog/Scenarios/Text.cs

@@ -88,16 +88,16 @@ namespace UICatalog.Scenarios {
 			var chxMultiline = new CheckBox ("Multiline") {
 				X = Pos.Left (textView),
 				Y = Pos.Bottom (textView),
-				Checked = true
+				Checked = textView.Multiline
 			};
-			chxMultiline.Toggled += (s,e) => textView.Multiline = (bool)e.OldValue;
 			Win.Add (chxMultiline);
 
 			var chxWordWrap = new CheckBox ("Word Wrap") {
 				X = Pos.Right (chxMultiline) + 2,
-				Y = Pos.Top (chxMultiline)
+				Y = Pos.Top (chxMultiline),
+				Checked = textView.WordWrap
 			};
-			chxWordWrap.Toggled += (s,e) => textView.WordWrap = (bool)e.OldValue;
+			chxWordWrap.Toggled += (s,e) => textView.WordWrap = (bool)e.NewValue;
 			Win.Add (chxWordWrap);
 
 			// TextView captures Tabs (so users can enter /t into text) by default;
@@ -106,20 +106,30 @@ namespace UICatalog.Scenarios {
 			var chxCaptureTabs = new CheckBox ("Capture Tabs") {
 				X = Pos.Right (chxWordWrap) + 2,
 				Y = Pos.Top (chxWordWrap),
-				Checked = true
+				Checked = textView.AllowsTab
+			};
+
+			chxMultiline.Toggled += (s, e) => {
+				textView.Multiline = (bool)e.NewValue;
+				if (!textView.Multiline && (bool)chxWordWrap.Checked) {
+					chxWordWrap.Checked = false;
+				}
+				if (!textView.Multiline && (bool)chxCaptureTabs.Checked) {
+					chxCaptureTabs.Checked = false;
+				}
 			};
 
 			Key keyTab = textView.GetKeyFromCommand (Command.Tab);
 			Key keyBackTab = textView.GetKeyFromCommand (Command.BackTab);
 			chxCaptureTabs.Toggled += (s,e) => {
-				if (e.OldValue == true) {
+				if (e.NewValue == true) {
 					textView.AddKeyBinding (keyTab, Command.Tab);
 					textView.AddKeyBinding (keyBackTab, Command.BackTab);
 				} else {
 					textView.ClearKeybinding (keyTab);
 					textView.ClearKeybinding (keyBackTab);
 				}
-				textView.WordWrap = (bool)e.OldValue;
+				textView.AllowsTab = (bool)e.NewValue;
 			};
 			Win.Add (chxCaptureTabs);
 

+ 10 - 0
UnitTests/Views/TextFieldTests.cs

@@ -1588,5 +1588,15 @@ Les Miśerables", output);
 			tf.ProcessKey (new KeyEvent (Key.CtrlMask | Key.CursorRight, new KeyModifiers () { Ctrl = true }));
 			Assert.Equal (22, tf.CursorPosition);
 		}
+
+		[Fact, TextFieldTestsAutoInitShutdown]
+		public void Cursor_Position_Initialization ()
+		{
+			Assert.False (_textField.IsInitialized);
+			Assert.Equal (32, _textField.CursorPosition);
+			Assert.Equal (0, _textField.SelectedLength);
+			Assert.Null (_textField.SelectedText);
+			Assert.Equal ("TAB to jump between text fields.", _textField.Text);
+		}
 	}
 }

+ 14 - 0
UnitTests/Views/TextViewTests.cs

@@ -6934,5 +6934,19 @@ This is the second line.
 			newPos = model.WordForward (4, 0);
 			Assert.Null (newPos);
 		}
+
+		[Fact, TextViewTestsAutoInitShutdown]
+		public void Cursor_Position_Multiline_False_Initialization ()
+		{
+			Assert.False (_textView.IsInitialized);
+			Assert.True (_textView.Multiline);
+			_textView.Multiline = false;
+			Assert.Equal (32, _textView.CursorPosition.X);
+			Assert.Equal (0, _textView.CursorPosition.Y);
+			Assert.Equal (0, _textView.SelectedLength);
+			Assert.Equal ("", _textView.SelectedText);
+			Assert.Equal ("TAB to jump between text fields.", _textView.Text);
+		}
+
 	}
 }

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio