瀏覽代碼

Avoids throw if _source is null.

BDisp 1 年之前
父節點
當前提交
fda698d1c4
共有 1 個文件被更改,包括 8 次插入3 次删除
  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>
     /// <returns></returns>
     public virtual bool MoveDown ()
     public virtual bool MoveDown ()
     {
     {
-        if (_source.Count == 0)
+        if (_source is null || _source.Count == 0)
         {
         {
             // Do we set lastSelectedItem to -1 here?
             // Do we set lastSelectedItem to -1 here?
             return false; //Nothing for us to move to
             return false; //Nothing for us to move to
@@ -479,7 +479,7 @@ public class ListView : View
     /// <returns></returns>
     /// <returns></returns>
     public virtual bool MoveEnd ()
     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;
             _selected = _source.Count - 1;
 
 
@@ -517,6 +517,11 @@ public class ListView : View
     /// <returns></returns>
     /// <returns></returns>
     public virtual bool MovePageDown ()
     public virtual bool MovePageDown ()
     {
     {
+        if (_source is null)
+        {
+            return true;
+        }
+
         int n = _selected + Bounds.Height;
         int n = _selected + Bounds.Height;
 
 
         if (n >= _source.Count)
         if (n >= _source.Count)
@@ -570,7 +575,7 @@ public class ListView : View
     /// <returns></returns>
     /// <returns></returns>
     public virtual bool MoveUp ()
     public virtual bool MoveUp ()
     {
     {
-        if (_source.Count == 0)
+        if (_source is null || _source.Count == 0)
         {
         {
             // Do we set lastSelectedItem to -1 here?
             // Do we set lastSelectedItem to -1 here?
             return false; //Nothing for us to move to
             return false; //Nothing for us to move to