Skip to content

Commit

Permalink
enhancement: freeze folders in place when reordering files
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingislost committed Feb 2, 2022
1 parent a0cbeb6 commit 57e44b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-bartender",
"name": "Bartender",
"version": "0.4.0",
"version": "0.4.1",
"minAppVersion": "0.12.5",
"description": "Allows for rearranging the elements in the status bar and sidebar ribbon",
"author": "NothingIsLost",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-bartender",
"name": "Bartender",
"version": "0.4.0",
"version": "0.4.1",
"minAppVersion": "0.12.5",
"description": "Allows for rearranging the elements in the status bar and sidebar ribbon",
"author": "NothingIsLost",
Expand Down
13 changes: 7 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,24 +508,25 @@ export default class BartenderPlugin extends Plugin {
}
},
onMove: evt => {
// TODO: Refactor this
// Responsible for updating the internal Obsidian array that contains the file item order
// Without this logic, reordering is ephemeral and will be undone by Obisidian's native processes
if (!root.children || !draggedItems?.length) return;
let children = root.children.map(child => child.el);
let adjacentEl = evt.related;
// root.children = move(root.children, children.indexOf(items[0]), children.indexOf(adjacentEl), items.length);
let targetIndex = children.indexOf(adjacentEl);
let firstItem = draggedItems.first();
if (!firstItem) return;
let firstItemIndex = children.indexOf(firstItem);
let _draggedItems: HTMLElement[];
if (firstItemIndex < targetIndex) _draggedItems = draggedItems.slice();
else _draggedItems = draggedItems.slice().reverse();
let firstItemIndex = children.indexOf(firstItem!);
let _draggedItems = draggedItems.slice();
if (firstItemIndex > targetIndex) _draggedItems.reverse();
for (let item of _draggedItems) {
let itemIndex = children.indexOf(item);
root.children = reorderArray(root.children, itemIndex, targetIndex);
children = reorderArray(children, itemIndex, targetIndex);
}
this.settings.fileExplorerOrder[root.file.path] = root.children.map(child => child.file.path);
this.saveSettings();
return !adjacentEl.hasClass('nav-folder');
},
onEnd: evt => {
draggedItems = [];
Expand Down

0 comments on commit 57e44b3

Please sign in to comment.