[gnome-shell/gbsneto/icon-grid-dnd-fixes: 1/14] appDisplay: Factor out linear position calculation




commit 6a11c413f80359a5406c4199be3dd38f11e0060d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Sep 23 16:48:43 2020 -0300

    appDisplay: Factor out linear position calculation
    
    When adding an item to the app grid, the item is added to
    a sorted array. This is calculated by adding all visible
    items in pages before the one being modified. Future commits
    will need this to move items without reparenting them, so
    factor this code into a separate function.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1447

 js/ui/appDisplay.js | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index f9e6a9b7da..9094fcf038 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -514,15 +514,10 @@ var BaseAppView = GObject.registerClass({
         return -1;
     }
 
-    _addItem(item, page, position) {
+    _getLinearPosition(page, position) {
         let itemIndex = 0;
 
         if (this._grid.nPages > 0) {
-            // Append icons to the first page with empty slot, starting from
-            // the second page
-            if (this._grid.nPages > 1 && page === -1 && position === -1)
-                page = this._findBestPageToAppend();
-
             const realPage = page === -1 ? this._grid.nPages - 1 : page;
 
             itemIndex = position === -1
@@ -535,6 +530,17 @@ var BaseAppView = GObject.registerClass({
             }
         }
 
+        return itemIndex;
+    }
+
+    _addItem(item, page, position) {
+        // Append icons to the first page with empty slot, starting from
+        // the second page
+        if (this._grid.nPages > 1 && page === -1 && position === -1)
+            page = this._findBestPageToAppend();
+
+        const itemIndex = this._getLinearPosition(page, position);
+
         this._orderedItems.splice(itemIndex, 0, item);
         this._items.set(item.id, item);
         this._grid.addItem(item, page, position);


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