mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Implement selectRange
This commit is contained in:
parent
376f543680
commit
00de99880b
2 changed files with 37 additions and 4 deletions
|
@ -39,8 +39,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
if (shift) {
|
if (shift) {
|
||||||
dispatch("tagrange");
|
dispatch("tagrange");
|
||||||
} else if (control) {
|
} else if (control) {
|
||||||
console.log("control", control);
|
dispatch("tagselect");
|
||||||
selected = !selected;
|
|
||||||
} else {
|
} else {
|
||||||
dispatch("tagedit");
|
dispatch("tagedit");
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,13 +279,46 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let selectionAnchor: number | null = null;
|
||||||
|
let selectionFocus: number | null = null;
|
||||||
|
|
||||||
|
function select(index: number) {
|
||||||
|
tags[index].selected = !tags[index].selected;
|
||||||
|
tags = tags;
|
||||||
|
|
||||||
|
selectionAnchor = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectRange(index: number) {
|
||||||
|
if (selectionAnchor === null) {
|
||||||
|
select(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectionFocus = index;
|
||||||
|
|
||||||
|
const from = Math.min(selectionAnchor, selectionFocus);
|
||||||
|
const to = Math.max(selectionAnchor, selectionFocus);
|
||||||
|
|
||||||
|
for (let index = from; index <= to; index++) {
|
||||||
|
tags[index].selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
function deselect() {
|
function deselect() {
|
||||||
tags = tags.map((tag: TagType): TagType => ({ ...tag, selected: false }));
|
tags = tags.map((tag: TagType): TagType => ({ ...tag, selected: false }));
|
||||||
|
selectionAnchor = null;
|
||||||
|
selectionFocus = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deselectIfLeave(event: FocusEvent) {
|
function deselectIfLeave(event: FocusEvent) {
|
||||||
const toolbar = event.currentTarget as HTMLDivElement;
|
const toolbar = event.currentTarget as HTMLDivElement;
|
||||||
if (!toolbar.contains(event.relatedTarget as Element)) {
|
if (
|
||||||
|
event.relatedTarget === null ||
|
||||||
|
!toolbar.contains(event.relatedTarget as Node)
|
||||||
|
) {
|
||||||
deselect();
|
deselect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +390,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
active = index;
|
active = index;
|
||||||
deselect();
|
deselect();
|
||||||
}}
|
}}
|
||||||
on:tagrange={console.log}
|
on:tagselect={() => select(index)}
|
||||||
|
on:tagrange={() => selectRange(index)}
|
||||||
on:tagdelete={() => {
|
on:tagdelete={() => {
|
||||||
deleteTagAt(index);
|
deleteTagAt(index);
|
||||||
saveTags();
|
saveTags();
|
||||||
|
|
Loading…
Reference in a new issue