From ed663c082419b1062c7cf5aa111edcc94d3a08b9 Mon Sep 17 00:00:00 2001 From: vineethvk11 Date: Mon, 18 Mar 2024 09:14:51 +0530 Subject: [PATCH] fixing issues in auto arrange while moving items --- src/UI/UIItem.js | 13 +++++++++++-- src/globals.js | 3 ++- src/helpers.js | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/UI/UIItem.js b/src/UI/UIItem.js index 3c8d547a..343ae553 100644 --- a/src/UI/UIItem.js +++ b/src/UI/UIItem.js @@ -188,7 +188,7 @@ function UIItem(options){ } // position - if(!is_auto_arrange_enabled && options.position && $(el_item).attr('data-path') !== trash_path){ + if(!is_auto_arrange_enabled && options.position && $(el_item).closest('.item-container').attr('data-path') === window.desktop_path){ el_item.style.position = 'absolute'; el_item.style.left = options.position.left + 'px'; el_item.style.top = options.position.top + 'px'; @@ -342,7 +342,9 @@ function UIItem(options){ } }, stop: function(event, ui){ - if(!is_auto_arrange_enabled && $(el_item).attr('data-path') !== trash_path){ + // Allow rearranging only if item is on desktop, not trash container, auto arrange is disabled and item is not dropped into another item + if($(el_item).closest('.item-container').attr('data-path') === window.desktop_path && + !is_auto_arrange_enabled && $(el_item).attr('data-path') !== trash_path && !ui.helper.data('dropped')){ el_item.style.position = 'absolute'; el_item.style.left = ui.position.left + 'px'; el_item.style.top = ui.position.top + 'px'; @@ -378,6 +380,9 @@ function UIItem(options){ if(event.ctrlKey && path.dirname($(ui.draggable).attr('data-path')) === window.trash_path) return; + // Adding a flag to know whether item is rearraged or dropped + ui.helper.data('dropped', true); + const items_to_move = [] // First item @@ -452,6 +457,10 @@ function UIItem(options){ } // Otherwise, move items else if(options.is_dir){ + if($(el_item).closest('.item-container').attr('data-path') === window.desktop_path){ + delete desktop_item_positions[$(el_item).attr('data-uid')]; + save_desktop_item_positions() + } move_items(items_to_move, $(el_item).attr('data-shortcut_to_path') !== '' ? $(el_item).attr('data-shortcut_to_path') : $(el_item).attr('data-path')); } } diff --git a/src/globals.js b/src/globals.js index 330d2007..4f7864e6 100644 --- a/src/globals.js +++ b/src/globals.js @@ -176,4 +176,5 @@ window.feature_flags = { } window.is_auto_arrange_enabled = true; -window.desktop_item_positions = {}; \ No newline at end of file +window.desktop_item_positions = {}; +window.reset_item_positions = true; // The variable decides if the item positions should be reset when the user enabled auto arrange \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index 3737d483..55133cff 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -3718,6 +3718,9 @@ window.clear_desktop_item_positions = async(el_desktop)=>{ $(el_item).css('left', ''); $(el_item).css('top', ''); }); + if(reset_item_positions){ + delete_desktop_item_positions() + } } window.set_desktop_item_positions = async(el_desktop)=>{ @@ -3735,3 +3738,8 @@ window.set_desktop_item_positions = async(el_desktop)=>{ window.save_desktop_item_positions = ()=>{ puter.kv.set('desktop_item_positions', desktop_item_positions); } + +window.delete_desktop_item_positions = ()=>{ + desktop_item_positions = {} + puter.kv.del('desktop_item_positions'); +} \ No newline at end of file