Skip to content

Commit

Permalink
respect order of notes/cards when duplicating
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Mar 17, 2024
1 parent a2b1f37 commit ea62d63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion duplicate_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aqt.qt import *
from aqt.utils import tooltip

from .merge_notes import notes_by_cards
from .config import config


Expand All @@ -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:
(
Expand Down
2 changes: 1 addition & 1 deletion merge_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down

0 comments on commit ea62d63

Please sign in to comment.