2
0
Эх сурвалжийг харах

Fixed indexes when closing a a large table and then opening a small table

tznind 4 жил өмнө
parent
commit
39b7ec4da9

+ 6 - 0
Terminal.Gui/Views/TableView.cs

@@ -223,6 +223,12 @@ namespace Terminal.Gui.Views {
 				return;
 			}
 
+			//if user opened a large table scrolled down a lot then opened a smaller table (or API deleted a bunch of columns without telling anyone)
+			ColumnOffset = Math.Max(Math.Min(ColumnOffset,Table.Columns.Count -1),0);
+			RowOffset = Math.Max(Math.Min(RowOffset,Table.Rows.Count -1),0);
+			SelectedColumn = Math.Max(Math.Min(SelectedColumn,Table.Columns.Count -1),0);
+			SelectedRow = Math.Max(Math.Min(SelectedRow,Table.Rows.Count -1),0);
+
 			Dictionary<DataColumn, int> columnsToRender = CalculateViewport (Bounds);
 
 			//if we have scrolled too far to the left 

+ 5 - 4
UICatalog/Scenarios/TableEditor.cs

@@ -25,7 +25,8 @@ namespace UICatalog.Scenarios {
 
 			var menu = new MenuBar (new MenuBarItem [] {
 				new MenuBarItem ("_File", new MenuItem [] {
-					new MenuItem ("_OpenExample", "", () => OpenExample()),
+					new MenuItem ("_OpenBigExample", "", () => OpenExample(true)),
+					new MenuItem ("_OpenSmallExample", "", () => OpenExample(false)),
 					new MenuItem ("_CloseExample", "", () => CloseExample()),
 					new MenuItem ("_Quit", "", () => Quit()),
 				}),
@@ -34,7 +35,7 @@ namespace UICatalog.Scenarios {
 
 			var statusBar = new StatusBar (new StatusItem [] {
 				//new StatusItem(Key.Enter, "~ENTER~ ApplyEdits", () => { _hexView.ApplyEdits(); }),
-				new StatusItem(Key.F2, "~F2~ OpenExample", () => OpenExample()),
+				new StatusItem(Key.F2, "~F2~ OpenExample", () => OpenExample(true)),
 				new StatusItem(Key.F3, "~F3~ EditCell", () => EditCurrentCell()),
 				new StatusItem(Key.F4, "~F4~ CloseExample", () => CloseExample()),
 				new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Quit()),
@@ -63,9 +64,9 @@ namespace UICatalog.Scenarios {
 			Application.RequestStop ();
 		}
 
-		private void OpenExample ()
+		private void OpenExample (bool big)
 		{
-			tableView.Table = BuildDemoDataTable(30,1000);
+			tableView.Table = BuildDemoDataTable(big ? 30 : 5, big ? 1000 : 5);
 		}
 
 		private void EditCurrentCell ()