[polari] roomList: Handle out-of-range indices in _roomToRowIndex()



commit 6ea7466678a1cec8fc424307d1fe5c912d9d5fab
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jan 29 23:19:57 2016 +0100

    roomList: Handle out-of-range indices in _roomToRowIndex()
    
    The current implementation throws an exception when trying to resolve
    the row index of a non-existent room index (for instance when activating
    the 'next-room' action from the last room). Reimplement the method to
    handle this case more gracefully.

 src/roomList.js |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index 5f2995c..56f19dc 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -423,13 +423,11 @@ const RoomList = new Lang.Class({
     },
 
     _roomToRowIndex: function(index) {
-        let roomRows = this.widget.get_children().filter(
-            function(r) {
-                return r.room != null;
-            }).sort(function(r1, r2) {
-                return r1.get_index() - r2.get_index();
-            });
-        return roomRows[index].get_index();
+        let nChildren = this.widget.get_children().length;
+        for (let i = 0, roomIndex = 0; i < nChildren; i++)
+            if (this.widget.get_row_at_index(i).room && roomIndex++ == index)
+                return i;
+        return -1;
     },
 
     _getRoomRowAtIndex: function(index) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]