rect file selection
This commit is contained in:
@@ -17,7 +17,7 @@ export const useWarrenStore = defineStore('warrens', {
|
||||
entries: DirectoryEntry[];
|
||||
} | null;
|
||||
} | null,
|
||||
selection: new Set() as Set<DirectoryEntry>,
|
||||
selection: new Map() as Map<string, DirectoryEntry>,
|
||||
selectionRangeAnchor: null as DirectoryEntry | null,
|
||||
loading: false,
|
||||
}),
|
||||
@@ -39,7 +39,9 @@ export const useWarrenStore = defineStore('warrens', {
|
||||
}
|
||||
|
||||
this.current.dir = {
|
||||
entries,
|
||||
entries: entries.toSorted((a, b) =>
|
||||
a.name.localeCompare(b.name)
|
||||
),
|
||||
parent,
|
||||
};
|
||||
},
|
||||
@@ -85,30 +87,38 @@ export const useWarrenStore = defineStore('warrens', {
|
||||
this.current = null;
|
||||
},
|
||||
addToSelection(entry: DirectoryEntry) {
|
||||
this.selection.add(entry);
|
||||
this.selection.set(entry.name, entry);
|
||||
},
|
||||
setSelection(entries: DirectoryEntry[]) {
|
||||
this.selection = new Set(entries);
|
||||
this.selection = entries.reduce(
|
||||
(acc, entry) => acc.set(entry.name, entry),
|
||||
new Map()
|
||||
);
|
||||
if (
|
||||
this.selectionRangeAnchor != null &&
|
||||
!this.selection.has(this.selectionRangeAnchor)
|
||||
!this.selection.has(this.selectionRangeAnchor.name)
|
||||
) {
|
||||
this.selectionRangeAnchor = null;
|
||||
}
|
||||
},
|
||||
addMultipleToSelection(entries: DirectoryEntry[]) {
|
||||
for (const entry of entries) {
|
||||
this.selection.add(entry);
|
||||
this.selection.set(entry.name, entry);
|
||||
}
|
||||
},
|
||||
removeMultipleFromSelection(entries: DirectoryEntry[]) {
|
||||
for (const entry of entries) {
|
||||
this.selection.delete(entry.name);
|
||||
}
|
||||
},
|
||||
setSelectedRangeAnchor(entry: DirectoryEntry) {
|
||||
this.selectionRangeAnchor = entry;
|
||||
},
|
||||
removeFromSelection(entry: DirectoryEntry): boolean {
|
||||
return this.selection.delete(entry);
|
||||
return this.selection.delete(entry.name);
|
||||
},
|
||||
toggleSelection(entry: DirectoryEntry): boolean {
|
||||
if (this.selection.has(entry)) {
|
||||
if (this.selection.has(entry.name)) {
|
||||
this.removeFromSelection(entry);
|
||||
return false;
|
||||
} else {
|
||||
@@ -121,7 +131,7 @@ export const useWarrenStore = defineStore('warrens', {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.selection.has(entry);
|
||||
return this.selection.has(entry.name);
|
||||
},
|
||||
clearSelection() {
|
||||
this.selection.clear();
|
||||
|
||||
Reference in New Issue
Block a user