AndyRussG has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/348310 )

Change subject: EmitterList: Fix moving an item to a lower index
......................................................................

EmitterList: Fix moving an item to a lower index

Bug: T163051
Change-Id: I13cfa3fae1cfb1c1f9700c10ca21b89be5075dbd
---
M src/EmitterList.js
M tests/unit/EmitterList.test.js
2 files changed, 14 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/core refs/changes/10/348310/1

diff --git a/src/EmitterList.js b/src/EmitterList.js
index 8a8f084..29d5b7a 100644
--- a/src/EmitterList.js
+++ b/src/EmitterList.js
@@ -222,8 +222,10 @@
                // Remove the item from the current index
                this.items.splice( existingIndex, 1 );
 
-               // Adjust new index after removal
-               newIndex--;
+               // If necessary, adjust new index after removal
+               if ( existingIndex < newIndex ) {
+                       newIndex--;
+               }
 
                // Move the item to the new index
                this.items.splice( newIndex, 0, item );
diff --git a/tests/unit/EmitterList.test.js b/tests/unit/EmitterList.test.js
index c67af21..03a24a4 100644
--- a/tests/unit/EmitterList.test.js
+++ b/tests/unit/EmitterList.test.js
@@ -67,7 +67,16 @@
                                                index: 2
                                        },
                                        expected: [ 'b', 'a', 'c' ],
-                                       msg: 'Moving duplicates when 
re-inserting an item'
+                                       msg: 'Moving duplicates when 
re-inserting an item at a higher index'
+                               },
+                               {
+                                       items: initialItems,
+                                       add: {
+                                               items: [ initialItems[ 2 ] ],
+                                               index: 0
+                                       },
+                                       expected: [ 'c', 'a', 'b' ],
+                                       msg: 'Moving duplicates when 
re-inserting an item at a lower index'
                                },
                                {
                                        items: initialItems,

-- 
To view, visit https://gerrit.wikimedia.org/r/348310
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I13cfa3fae1cfb1c1f9700c10ca21b89be5075dbd
Gerrit-PatchSet: 1
Gerrit-Project: oojs/core
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <andrew.green...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to