mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-11 16:24:11 +01:00
Clipboard: Enforce MaxItems limit when performing range-selects #271
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -125,13 +125,12 @@ export class Clipboard {
|
||||
|
||||
const id = model.getId();
|
||||
|
||||
this.addId(id);
|
||||
return this.addId(id);
|
||||
}
|
||||
|
||||
addId(id) {
|
||||
this.updateDom(id, true);
|
||||
|
||||
if (this.hasId(id)) {
|
||||
this.lastId = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,6 +144,7 @@ export class Clipboard {
|
||||
this.lastId = id;
|
||||
|
||||
this.saveToStorage();
|
||||
this.updateDom(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -170,12 +170,19 @@ export class Clipboard {
|
||||
rangeEnd = newEnd;
|
||||
}
|
||||
|
||||
let added = 0;
|
||||
|
||||
for (let i = rangeStart; i <= rangeEnd; i++) {
|
||||
this.add(models[i], false);
|
||||
this.updateDom(models[i].getId(), true);
|
||||
const result = this.add(models[i]);
|
||||
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
|
||||
added++;
|
||||
}
|
||||
|
||||
return rangeEnd - rangeStart + 1;
|
||||
return added;
|
||||
}
|
||||
|
||||
has(model) {
|
||||
|
||||
@@ -192,4 +192,21 @@ describe("common/clipboard", () => {
|
||||
clipboard.addRange(3, Photos);
|
||||
expect(clipboard.selection.length).toBe(4);
|
||||
});
|
||||
|
||||
it("should respect maxItems when adding a range", () => {
|
||||
const storage = new StorageShim();
|
||||
const clipboard = new Clipboard(storage, "clipboard");
|
||||
clipboard.maxItems = 2;
|
||||
|
||||
const models = [new Photo({ UID: "P1" }), new Photo({ UID: "P2" }), new Photo({ UID: "P3" })];
|
||||
|
||||
clipboard.add(models[0]);
|
||||
expect(clipboard.selection.length).toBe(1);
|
||||
|
||||
const added = clipboard.addRange(2, models);
|
||||
|
||||
expect(added).toBe(2);
|
||||
expect(clipboard.selection.length).toBe(2);
|
||||
expect(clipboard.selection).toEqual(["P1", "P2"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user