Skip to content

Commit

Permalink
Small refactor to move selection logic into tree-selection
Browse files Browse the repository at this point in the history
Teach tree-selection how to determine if a node or any of its parents
are selected, and leverage that logic in the UI code (rather than
open-coding it in the UI directly).
  • Loading branch information
josh-berry committed Jul 30, 2023
1 parent ee66802 commit 0ce76dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/model/tree-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ export class TreeSelection<
for (const c of node.children) yield* this.selectedItemsInSubtree(c);
}

/** Check if the provided node or any of its parents is selected. Useful for
* precluding things like moving a node into a child of itself. */
isSelfOrParentSelected(node?: P | N): boolean {
while (node) {
const si = this.info(node);
if (si.isSelected) return true;
node = node.position?.parent;
}
return false;
}

/** Set all `node.isSelected` properties to false within `this.roots`. */
clearSelection(): void {
this.lastSelected = undefined;
Expand Down
8 changes: 1 addition & 7 deletions src/stash-list/folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,7 @@ export default defineComponent({
},
canMoveIntoFolder(): boolean {
let f: Folder | undefined = this.folder;
while (f) {
const si = the.model.selection.info(f);
if (si.isSelected) return false;
f = f.position?.parent;
}
return true;
return !the.model.selection.isSelfOrParentSelected(this.folder);
},
},
Expand Down

0 comments on commit 0ce76dc

Please sign in to comment.