From e29771fa48c51eb7fce38a78338b0e44a0e5c048 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 22 Aug 2016 01:39:34 -0400 Subject: [PATCH] base: Fix broken move logic Sometime I wonder WTF I was on when I wrote some parts or Radical... I guess I can call it university stress... Note that this will probably cause a bunch of regressions because some other code expected the garbage I was creating. --- base.lua | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/base.lua b/base.lua index 2cf3984..2b59979 100644 --- a/base.lua +++ b/base.lua @@ -558,21 +558,15 @@ local function new(args) break end end - if idx1 then --- if idx < idx1 then --- idx = idx + 1 --- end - if idx1 > #internal.items + 1 then - idx1 = #internal.items + 1 - end - if idx ~= idx1 then - table.insert(internal.items,idx1,table.remove(internal.items,idx)) - item.index = idx - data:emit_signal("item::moved",item,idx,idx1) - for i=idx,idx1 do - internal.items[i].index = i - end + if idx1 and idx ~= idx1 then + table.remove(internal.items,idx1) + table.insert(internal.items,idx, item) + + for i=math.min(idx,idx1), idx1 > idx and idx1 or #internal.items do + internal.items[i].index = i end + + data:emit_signal("item::moved",item,idx,idx1) end end