Skip to content

Commit

Permalink
Fixes gui-cs#1866. Bug when scrolling text and type in a TextView.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Jul 21, 2022
1 parent 40b661d commit 293af69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ void Insert (Rune rune)
}
var prow = currentRow - topRow;
if (!wrapNeeded) {
SetNeedsDisplay (new Rect (0, prow, Frame.Width, prow + 1));
SetNeedsDisplay (new Rect (0, prow, Math.Max (Frame.Width, 0), Math.Max (prow + 1, 0)));
}
}

Expand Down
20 changes: 20 additions & 0 deletions UnitTests/TextViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5707,5 +5707,25 @@ public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
});
Assert.Null (exception);
}

[Fact]
[AutoInitShutdown]
public void ScrollDownTillCaretOffscreen_ThenType ()
{
var tv = new TextView {
Width = 10,
Height = 5
};

// add 100 lines of wide text to view
for (int i = 0; i < 100; i++)
tv.Text += new string ('x', 100) + Environment.NewLine;

Assert.Equal (0, tv.CursorPosition.Y);
tv.ScrollTo (50);
Assert.Equal (0, tv.CursorPosition.Y);

tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ()));
}
}
}

0 comments on commit 293af69

Please sign in to comment.