浏览代码

Fixed out of range exception and text redraw when navigate backward (#320)

BDisp 5 年之前
父节点
当前提交
35591b8399
共有 1 个文件被更改,包括 13 次插入12 次删除
  1. 13 12
      Terminal.Gui/Views/TextView.cs

+ 13 - 12
Terminal.Gui/Views/TextView.cs

@@ -807,7 +807,7 @@ namespace Terminal.Gui {
 						currentRow--;
 						if (currentRow < topRow) {
 							topRow--;
-
+							SetNeedsDisplay ();
 						}
 						currentLine = GetCurrentLine ();
 						currentColumn = currentLine.Count;
@@ -1149,18 +1149,19 @@ namespace Terminal.Gui {
 				SuperView.SetFocus (this);
 
 
-			var maxCursorPositionableLine = (model.Count - 1) - topRow;
-			if (ev.Y > maxCursorPositionableLine) {
-				currentRow = maxCursorPositionableLine;
-			} else {
-				currentRow = ev.Y + topRow;
+			if (model.Count > 0) {
+				var maxCursorPositionableLine = (model.Count - 1) - topRow;
+				if (ev.Y > maxCursorPositionableLine) {
+					currentRow = maxCursorPositionableLine;
+				} else {
+					currentRow = ev.Y + topRow;
+				}
+				var r = GetCurrentLine ();
+				if (ev.X - leftColumn >= r.Count)
+					currentColumn = r.Count - leftColumn;
+				else
+					currentColumn = ev.X - leftColumn;
 			}
-			var r = GetCurrentLine ();
-			if (ev.X - leftColumn >= r.Count)
-				currentColumn = r.Count - leftColumn;
-			else
-				currentColumn = ev.X - leftColumn;
-
 			PositionCursor ();
 			return true;
 		}