mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-08 20:19:06 +03:00
fixed multiple selection actions in list manager
This commit is contained in:
@@ -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 (toDuplicate.length === 0) return;
|
||||||
|
const sortedDesc = [...toDuplicate].sort((a, b) => b - a);
|
||||||
|
sortedDesc.forEach(index => {
|
||||||
|
const list = this.lists[index];
|
||||||
if (!list) return;
|
if (!list) return;
|
||||||
const newList: HighlightList = {
|
const newList: HighlightList = {
|
||||||
id: Date.now(),
|
id: Date.now() + Math.random(),
|
||||||
name: `${list.name} (Copy)`,
|
name: `${list.name} (Copy)`,
|
||||||
background: list.background,
|
background: list.background,
|
||||||
foreground: list.foreground,
|
foreground: list.foreground,
|
||||||
active: list.active,
|
active: list.active,
|
||||||
words: list.words.map(word => ({ ...word }))
|
words: list.words.map(word => ({ ...word }))
|
||||||
};
|
};
|
||||||
this.lists.splice(this.currentListIndex + 1, 0, newList);
|
this.lists.splice(index + 1, 0, newList);
|
||||||
this.currentListIndex = this.currentListIndex + 1;
|
});
|
||||||
|
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;
|
|
||||||
if (!confirm(chrome.i18n.getMessage('delete_current_list') || 'Delete current list?')) return;
|
|
||||||
this.lists.splice(this.currentListIndex, 1);
|
|
||||||
} else {
|
|
||||||
const confirmMessage = chrome.i18n.getMessage('delete_lists_confirm')
|
const confirmMessage = chrome.i18n.getMessage('delete_lists_confirm')
|
||||||
?.replace('{count}', String(selected.length))
|
?.replace('{count}', String(selected.length))
|
||||||
|| `Delete ${selected.length} selected list(s)?`;
|
|| `Delete ${selected.length} selected list(s)?`;
|
||||||
if (!confirm(confirmMessage)) return;
|
if (!confirm(confirmMessage)) return;
|
||||||
selected.sort((a, b) => b - a).forEach(index => this.lists.splice(index, 1));
|
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 }));
|
||||||
|
|||||||
Reference in New Issue
Block a user