Переглянути джерело

Merge pull request #1025 from BDisp/textview-newline

Fixes #1024. TextView is printing the new line character "\n" with a symbol.
Charlie Kindel 4 роки тому
батько
коміт
d782bf62f7
1 змінених файлів з 23 додано та 4 видалено
  1. 23 4
      Terminal.Gui/Views/TextView.cs

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

@@ -419,7 +419,13 @@ namespace Terminal.Gui {
 
 				SetNeedsDisplay (new Rect (0, minRow, Frame.Width, maxRow));
 			}
-			Move (CurrentColumn - leftColumn, CurrentRow - topRow);
+			var line = model.GetLine (currentRow);
+			var retreat = 0;
+			if (line.Count > 0) {
+				retreat = Math.Max ((SpecialRune (line [Math.Max (CurrentColumn - leftColumn - 1, 0)])
+				? 1 : 0), 0);
+			}
+			Move (CurrentColumn - leftColumn - retreat, CurrentRow - topRow);
 		}
 
 		void ClearRegion (int left, int top, int right, int bottom)
@@ -566,17 +572,30 @@ namespace Terminal.Gui {
 				for (int col = bounds.Left; col < right; col++) {
 					var lineCol = leftColumn + col;
 					var rune = lineCol >= lineRuneCount ? ' ' : line [lineCol];
-					if (selecting && PointInSelection (col, row))
+					if (selecting && PointInSelection (col, row)) {
 						ColorSelection ();
-					else
+					} else {
 						ColorNormal ();
+					}
 
-					AddRune (col, row, rune);
+					if (!SpecialRune (rune)) {
+						AddRune (col, row, rune);
+					}
 				}
 			}
 			PositionCursor ();
 		}
 
+		bool SpecialRune (Rune rune)
+		{
+			switch (rune) {
+			case (uint)Key.Enter:
+			case 0xd:
+				return true;
+			default:
+				return false;			}
+		}
+
 		///<inheritdoc/>
 		public override bool CanFocus {
 			get => base.CanFocus;