Przeglądaj źródła

Fixes the CalculateLeftColumn method avoiding jump two columns on forward moving.

BDisp 3 lat temu
rodzic
commit
2513dbc0f9

+ 1 - 1
Terminal.Gui/Views/TextField.cs

@@ -90,7 +90,7 @@ namespace Terminal.Gui {
 
 
 			this.text = TextModel.ToRunes (text.Split ("\n") [0]);
 			this.text = TextModel.ToRunes (text.Split ("\n") [0]);
 			point = text.RuneCount;
 			point = text.RuneCount;
-			first = point > w ? point - w : 0;
+			first = point > w + 1 ? point - w + 1 : 0;
 			CanFocus = true;
 			CanFocus = true;
 			Used = true;
 			Used = true;
 			WantMousePositionReports = true;
 			WantMousePositionReports = true;

+ 4 - 1
Terminal.Gui/Views/TextView.cs

@@ -303,7 +303,10 @@ namespace Terminal.Gui {
 				if (rune == '\t') {
 				if (rune == '\t') {
 					size += tabWidth + 1;
 					size += tabWidth + 1;
 				}
 				}
-				if (size >= width) {
+				if (size > width) {
+					if (col + width == end) {
+						col++;
+					}
 					break;
 					break;
 				} else if (end < t.Count && col > 0 && start < end && col == start) {
 				} else if (end < t.Count && col > 0 && start < end && col == start) {
 					break;
 					break;

+ 7 - 4
UnitTests/TextViewTests.cs

@@ -1809,7 +1809,10 @@ namespace Terminal.Gui.Views {
 				if (r == '\t') {
 				if (r == '\t') {
 					sumLength += tabWidth + 1;
 					sumLength += tabWidth + 1;
 				}
 				}
-				if (sumLength >= width) {
+				if (sumLength > width) {
+					if (col + width == cCol) {
+						col++;
+					}
 					break;
 					break;
 				} else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
 				} else if (cCol < line.Length && col > 0 && start < cCol && col == start) {
 					break;
 					break;
@@ -1987,9 +1990,9 @@ line.
 			Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
 			Assert.Equal ((15, 15), TextModel.DisplaySize (txtRunes));
 			Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
 			Assert.Equal ((6, 6), TextModel.DisplaySize (txtRunes, 1, 7));
 
 
-			Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
-			Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
-			Assert.Equal (3, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
+			Assert.Equal (0, TextModel.CalculateLeftColumn (txtRunes, 0, 7, 8));
+			Assert.Equal (1, TextModel.CalculateLeftColumn (txtRunes, 0, 8, 8));
+			Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8));
 
 
 			var tm = new TextModel ();
 			var tm = new TextModel ();
 			tm.AddLine (0, TextModel.ToRunes ("This is first line."));
 			tm.AddLine (0, TextModel.ToRunes ("This is first line."));