diff --git a/duplicate_notes.py b/duplicate_notes.py index 45a58e2..ca61bf6 100644 --- a/duplicate_notes.py +++ b/duplicate_notes.py @@ -11,6 +11,7 @@ from aqt.qt import * from aqt.utils import tooltip +from .merge_notes import notes_by_cards from .config import config @@ -32,8 +33,18 @@ def duplicate_notes_op(col: Collection, notes: Sequence[Note]) -> OpChanges: return col.merge_undo_entries(pos) +def get_notes_keeping_order(browser: Browser) -> list[Note]: + """ + Retrieve notes in the order they're shown in Browser. + """ + if browser.table.is_notes_mode(): + return [browser.col.get_note(note_id) for note_id in browser.selected_notes()] + else: + return notes_by_cards(browser.col.get_card(card_id) for card_id in browser.selected_cards()) + + def duplicate_notes(browser: Browser) -> None: - notes = [browser.col.get_note(note_id) for note_id in browser.selected_notes()] + notes: list[Note] = get_notes_keeping_order(browser) if len(notes) > 0: ( diff --git a/merge_notes.py b/merge_notes.py index dc50b0b..f451649 100644 --- a/merge_notes.py +++ b/merge_notes.py @@ -151,7 +151,7 @@ def _merge_notes(self, notes: Sequence[Note]): self.notes_to_update.extend(notes) -def notes_by_cards(cards: Sequence[Card]) -> list[Note]: +def notes_by_cards(cards: Iterable[Card]) -> list[Note]: return list({(note := card.note()).id: note for card in cards}.values())