Browse Source

TextView MoveHome and MoveEnd methods.

blakepell 4 years ago
parent
commit
6119547df3
1 changed files with 34 additions and 6 deletions
  1. 34 6
      Terminal.Gui/Views/TextView.cs

+ 34 - 6
Terminal.Gui/Views/TextView.cs

@@ -234,6 +234,18 @@ namespace Terminal.Gui {
 	///        </description>
 	///     </item>
 	///     <item>
+	///        <term>Control-Home</term>
+	///        <description>
+	///          Scrolls to the first line and moves the cursor there.
+	///        </description>
+	///     </item>
+	///     <item>
+	///        <term>Control-End</term>
+	///        <description>
+	///          Scrolls to the last line and moves the cursor there.
+	///        </description>
+	///     </item>
+	///     <item>
 	///        <term>Delete, Control-d</term>
 	///        <description>
 	///          Deletes the character in front of the cursor.
@@ -1004,15 +1016,11 @@ namespace Terminal.Gui {
 				break;
 
 			case Key.CtrlMask | Key.End:
-				currentRow = model.Count;
-				TrackColumn ();
-				PositionCursor ();
+				MoveEnd ();
 				break;
 
 			case Key.CtrlMask | Key.Home:
-				currentRow = 0;
-				TrackColumn ();
-				PositionCursor ();
+				MoveHome ();
 				break;
 
 			default:
@@ -1086,6 +1094,26 @@ namespace Terminal.Gui {
 
 		Rune RuneAt (int col, int row) => model.GetLine (row) [col];
 
+		/// <summary>
+		/// Will scroll the <see cref="TextView"/> to the last line and position the cursor there.
+		/// </summary>
+		public void MoveEnd ()
+		{
+			currentRow = model.Count - 1;
+			TrackColumn ();
+			PositionCursor ();
+		}
+
+		/// <summary>
+		/// Will scroll the <see cref="TextView"/> to the first line and position the cursor there.
+		/// </summary>
+		public void MoveHome ()
+		{
+			currentRow = 0;
+			TrackColumn ();
+			PositionCursor ();
+		}
+
 		bool MoveNext (ref int col, ref int row, out Rune rune)
 		{
 			var line = model.GetLine (row);