浏览代码

Fix paste not working and invoke ContentsChanged where is needed. Add unit test.

BDisp 2 年之前
父节点
当前提交
20650213c2
共有 2 个文件被更改,包括 43 次插入2 次删除
  1. 11 0
      Terminal.Gui/Views/TextView.cs
  2. 32 2
      UnitTests/Views/TextViewTests.cs

+ 11 - 0
Terminal.Gui/Views/TextView.cs

@@ -2639,6 +2639,7 @@ namespace Terminal.Gui {
 				HistoryText.LineStatus.Replaced);
 
 			UpdateWrapModel ();
+			OnContentsChanged ();
 		}
 
 		// The column we are tracking, or -1 if we are not tracking any column
@@ -3568,6 +3569,7 @@ namespace Terminal.Gui {
 			}
 			if (DeleteTextForwards ()) {
 				UpdateWrapModel ();
+				OnContentsChanged ();
 
 				return;
 			}
@@ -3575,6 +3577,7 @@ namespace Terminal.Gui {
 			UpdateWrapModel ();
 
 			DoNeededAction ();
+			OnContentsChanged ();
 		}
 
 		/// <summary>
@@ -3599,11 +3602,13 @@ namespace Terminal.Gui {
 					HistoryText.LineStatus.Replaced);
 
 				UpdateWrapModel ();
+				OnContentsChanged ();
 
 				return;
 			}
 			if (DeleteTextBackwards ()) {
 				UpdateWrapModel ();
+				OnContentsChanged ();
 
 				return;
 			}
@@ -3611,6 +3616,7 @@ namespace Terminal.Gui {
 			UpdateWrapModel ();
 
 			DoNeededAction ();
+			OnContentsChanged ();
 		}
 
 		void MoveLeft ()
@@ -3990,6 +3996,8 @@ namespace Terminal.Gui {
 
 				historyText.Add (new List<List<Rune>> () { new List<Rune> (GetCurrentLine ()) }, CursorPosition,
 					HistoryText.LineStatus.Replaced);
+
+				SetNeedsDisplay ();
 				OnContentsChanged ();
 			} else {
 				if (selecting) {
@@ -4002,6 +4010,8 @@ namespace Terminal.Gui {
 					historyText.ReplaceLast (new List<List<Rune>> () { new List<Rune> (GetCurrentLine ()) }, CursorPosition,
 						HistoryText.LineStatus.Original);
 				}
+
+				SetNeedsDisplay ();
 			}
 			UpdateWrapModel ();
 			selecting = false;
@@ -4113,6 +4123,7 @@ namespace Terminal.Gui {
 			currentColumn = line.Count;
 			TrackColumn ();
 			PositionCursor ();
+			SetNeedsDisplay ();
 		}
 
 		/// <summary>

+ 32 - 2
UnitTests/Views/TextViewTests.cs

@@ -6634,11 +6634,11 @@ This is the second line.
 			Kill_Delete_WordBackward ();
 			Assert.Equal (expectedEventCount, eventcount);
 
-			expectedEventCount += 1;
+			expectedEventCount += 2;
 			Kill_To_End_Delete_Forwards_And_Copy_To_The_Clipboard ();
 			Assert.Equal (expectedEventCount, eventcount);
 
-			expectedEventCount += 1;
+			expectedEventCount += 2;
 			Kill_To_Start_Delete_Backwards_And_Copy_To_The_Clipboard ();
 			Assert.Equal (expectedEventCount, eventcount);
 		}
@@ -6827,5 +6827,35 @@ This is the second line.
 			Assert.Null (exception);
 			Assert.Equal (textToReplace, tv.Text);
 		}
+
+		[Fact]
+		[TextViewTestsAutoInitShutdown]
+		public void Paste_Always_Render_Screen ()
+		{
+			var win = new Window ();
+			win.Border.BorderStyle = BorderStyle.None;
+			win.Border.DrawMarginFrame = false;
+			win.Add (_textView);
+			Application.Top.Add (win);
+			Application.Begin (Application.Top);
+
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+TAB to jump between text field", output);
+
+			Assert.True (_textView.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers () { Shift = true }))); // Select line
+			Assert.Equal ("TAB to jump between text fields.", _textView.SelectedText);
+			Assert.True (_textView.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ()))); // Copy
+			Assert.Equal ("TAB to jump between text fields.", Clipboard.Contents);
+			Assert.True (_textView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ()))); // Go to end of line
+			Assert.True (_textView.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ()))); // New line
+			Assert.Equal (new Point (0, 1), _textView.CursorPosition);
+			Assert.Equal ("", _textView.SelectedText);
+			Assert.True (_textView.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ()))); // Paste
+			Assert.Equal ($"TAB to jump between text fields.{Environment.NewLine}TAB to jump between text fields.", _textView.Text);
+			win.Redraw (win.Bounds);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+ to jump between text fields.
+ to jump between text fields.", output);
+		}
 	}
 }