Browse Source

Avoids throw if _source is null.

BDisp 1 year ago
parent
commit
fda698d1c4
1 changed files with 8 additions and 3 deletions
  1. 8 3
      Terminal.Gui/Views/ListView.cs

+ 8 - 3
Terminal.Gui/Views/ListView.cs

@@ -429,7 +429,7 @@ public class ListView : View
     /// <returns></returns>
     public virtual bool MoveDown ()
     {
-        if (_source.Count == 0)
+        if (_source is null || _source.Count == 0)
         {
             // Do we set lastSelectedItem to -1 here?
             return false; //Nothing for us to move to
@@ -479,7 +479,7 @@ public class ListView : View
     /// <returns></returns>
     public virtual bool MoveEnd ()
     {
-        if (_source.Count > 0 && _selected != _source.Count - 1)
+        if (_source is { Count: > 0 } && _selected != _source.Count - 1)
         {
             _selected = _source.Count - 1;
 
@@ -517,6 +517,11 @@ public class ListView : View
     /// <returns></returns>
     public virtual bool MovePageDown ()
     {
+        if (_source is null)
+        {
+            return true;
+        }
+
         int n = _selected + Bounds.Height;
 
         if (n >= _source.Count)
@@ -570,7 +575,7 @@ public class ListView : View
     /// <returns></returns>
     public virtual bool MoveUp ()
     {
-        if (_source.Count == 0)
+        if (_source is null || _source.Count == 0)
         {
             // Do we set lastSelectedItem to -1 here?
             return false; //Nothing for us to move to