fixed multiple selection actions in list manager

This commit is contained in:
2026-02-06 12:40:37 +03:00
parent 592cce580e
commit 9294593975

View File

@@ -120,24 +120,30 @@ const wordSearch = document.getElementById('wordSearch') as HTMLInputElement;
} }
private duplicateCurrentList(): void { private duplicateCurrentList(): void {
const list = this.lists[this.currentListIndex]; const toDuplicate = this.getEffectiveSelectedListIndices();
if (!list) return; if (toDuplicate.length === 0) return;
const newList: HighlightList = { const sortedDesc = [...toDuplicate].sort((a, b) => b - a);
id: Date.now(), sortedDesc.forEach(index => {
name: `${list.name} (Copy)`, const list = this.lists[index];
background: list.background, if (!list) return;
foreground: list.foreground, const newList: HighlightList = {
active: list.active, id: Date.now() + Math.random(),
words: list.words.map(word => ({ ...word })) name: `${list.name} (Copy)`,
}; background: list.background,
this.lists.splice(this.currentListIndex + 1, 0, newList); foreground: list.foreground,
this.currentListIndex = this.currentListIndex + 1; active: list.active,
words: list.words.map(word => ({ ...word }))
};
this.lists.splice(index + 1, 0, newList);
});
const firstInsertedIndex = Math.min(...toDuplicate) + 1;
this.currentListIndex = Math.min(firstInsertedIndex, this.lists.length - 1);
this.selectedLists.clear(); this.selectedLists.clear();
this.save(); this.save();
} }
private mergeSelectedLists(): void { private mergeSelectedLists(): void {
const selected = this.getSelectedListIndices(); const selected = this.getEffectiveSelectedListIndices();
if (selected.length < 2) { if (selected.length < 2) {
alert(chrome.i18n.getMessage('merge_lists_min_two') || 'Select at least two lists to merge.'); alert(chrome.i18n.getMessage('merge_lists_min_two') || 'Select at least two lists to merge.');
return; return;
@@ -168,18 +174,13 @@ const wordSearch = document.getElementById('wordSearch') as HTMLInputElement;
} }
private deleteSelectedLists(): void { private deleteSelectedLists(): void {
const selected = this.getSelectedListIndices(); const selected = this.getEffectiveSelectedListIndices();
if (selected.length === 0) { if (selected.length === 0) return;
if (!this.lists[this.currentListIndex]) return; const confirmMessage = chrome.i18n.getMessage('delete_lists_confirm')
if (!confirm(chrome.i18n.getMessage('delete_current_list') || 'Delete current list?')) return; ?.replace('{count}', String(selected.length))
this.lists.splice(this.currentListIndex, 1); || `Delete ${selected.length} selected list(s)?`;
} else { if (!confirm(confirmMessage)) return;
const confirmMessage = chrome.i18n.getMessage('delete_lists_confirm') selected.sort((a, b) => b - a).forEach(index => this.lists.splice(index, 1));
?.replace('{count}', String(selected.length))
|| `Delete ${selected.length} selected list(s)?`;
if (!confirm(confirmMessage)) return;
selected.sort((a, b) => b - a).forEach(index => this.lists.splice(index, 1));
}
if (this.lists.length === 0) { if (this.lists.length === 0) {
this.createList(); this.createList();
@@ -752,6 +753,13 @@ const wordSearch = document.getElementById('wordSearch') as HTMLInputElement;
return Array.from(this.selectedLists).filter(index => this.lists[index]); return Array.from(this.selectedLists).filter(index => this.lists[index]);
} }
/** Current list plus any Ctrl+clicked lists (effective selection for merge/duplicate/delete). */
private getEffectiveSelectedListIndices(): number[] {
const indices = new Set(this.getSelectedListIndices());
indices.add(this.currentListIndex);
return Array.from(indices).filter(index => this.lists[index]);
}
private getFilteredWordEntries(list: HighlightList): Array<{ word: HighlightWord; index: number }> { private getFilteredWordEntries(list: HighlightList): Array<{ word: HighlightWord; index: number }> {
const query = this.wordSearchQuery.trim().toLowerCase(); const query = this.wordSearchQuery.trim().toLowerCase();
const entries = list.words.map((word, index) => ({ word, index })); const entries = list.words.map((word, index) => ({ word, index }));