Adjust the top considering the selected item and the frame height.

This commit is contained in:
BDisp
2024-05-29 12:34:59 +01:00
parent d7b0899f2b
commit d5bf412d37
2 changed files with 13 additions and 11 deletions

View File

@@ -601,10 +601,12 @@ namespace Terminal.Gui {
/// <returns></returns>
public virtual bool MoveEnd ()
{
if (source.Count > 0 && selected != source.Count - 1) {
if (source?.Count > 0 && selected != source.Count - 1) {
selected = source.Count - 1;
if (top + selected > Frame.Height - 1) {
top = selected;
top = selected < Frame.Height - 1
? Math.Max (Frame.Height - selected + 1, 0)
: Math.Max (selected - Frame.Height + 1, 0);
}
OnSelectedChanged ();
SetNeedsDisplay ();

View File

@@ -300,16 +300,16 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (19, lv.SelectedItem);
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌──────────┐
│Line10 │
│Line11 │
│Line12 │
│Line13 │
│Line14 │
│Line15 │
│Line16 │
│Line17 │
│Line18 │
│Line19 │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────┘", output);
Assert.True (lv.ScrollUp (20));