fix note changes triggering a queue rebuild

This commit is contained in:
Damien Elmes 2021-06-08 12:09:35 +10:00
parent df600c094a
commit 1479957538
9 changed files with 15 additions and 29 deletions

View File

@ -116,7 +116,7 @@ class Browser(QMainWindow):
focused = current_window() == self focused = current_window() == self
self.table.op_executed(changes, handler, focused) self.table.op_executed(changes, handler, focused)
self.sidebar.op_executed(changes, handler, focused) self.sidebar.op_executed(changes, handler, focused)
if changes.editor: if changes.note_text:
if handler is not self.editor: if handler is not self.editor:
# fixme: this will leave the splitter shown, but with no current # fixme: this will leave the splitter shown, but with no current
# note being edited # note being edited

View File

@ -81,7 +81,7 @@ class DeckBrowser:
def op_executed( def op_executed(
self, changes: OpChanges, handler: Optional[object], focused: bool self, changes: OpChanges, handler: Optional[object], focused: bool
) -> bool: ) -> bool:
if changes.reviewer and handler is not self: if changes.study_queues and handler is not self:
self._refresh_needed = True self._refresh_needed = True
if focused: if focused:

View File

@ -34,7 +34,7 @@ class EditCurrent(QDialog):
def on_operation_did_execute( def on_operation_did_execute(
self, changes: OpChanges, handler: Optional[object] self, changes: OpChanges, handler: Optional[object]
) -> None: ) -> None:
if changes.editor and handler is not self.editor: if changes.note_text and handler is not self.editor:
# reload note # reload note
note = self.editor.note note = self.editor.note
try: try:

View File

@ -74,7 +74,7 @@ class Overview:
def op_executed( def op_executed(
self, changes: OpChanges, handler: Optional[object], focused: bool self, changes: OpChanges, handler: Optional[object], focused: bool
) -> bool: ) -> bool:
if changes.reviewer: if changes.study_queues:
self._refresh_needed = True self._refresh_needed = True
if focused: if focused:

View File

@ -169,9 +169,9 @@ class Reviewer:
self, changes: OpChanges, handler: Optional[object], focused: bool self, changes: OpChanges, handler: Optional[object], focused: bool
) -> bool: ) -> bool:
if handler is not self: if handler is not self:
if changes.reviewer: if changes.study_queues:
self._refresh_needed = RefreshNeeded.QUEUES self._refresh_needed = RefreshNeeded.QUEUES
elif changes.editor: elif changes.note_text:
self._refresh_needed = RefreshNeeded.NOTE_TEXT self._refresh_needed = RefreshNeeded.NOTE_TEXT
if focused and self._refresh_needed: if focused and self._refresh_needed:

View File

@ -1578,8 +1578,10 @@ message OpChanges {
bool browser_table = 7; bool browser_table = 7;
bool browser_sidebar = 8; bool browser_sidebar = 8;
bool editor = 9; // editor and displayed card in review screen
bool reviewer = 10; bool note_text = 9;
// whether to call .reset() and getCard()
bool study_queues = 10;
} }
message UndoStatus { message UndoStatus {

View File

@ -21,8 +21,8 @@ impl From<OpChanges> for pb::OpChanges {
mtime: c.changes.mtime, mtime: c.changes.mtime,
browser_table: c.requires_browser_table_redraw(), browser_table: c.requires_browser_table_redraw(),
browser_sidebar: c.requires_browser_sidebar_redraw(), browser_sidebar: c.requires_browser_sidebar_redraw(),
editor: c.requires_editor_redraw(), note_text: c.requires_note_text_redraw(),
reviewer: c.requires_reviewer_redraw(), study_queues: c.requires_study_queue_rebuild(),
} }
} }
} }

View File

@ -149,29 +149,13 @@ impl OpChanges {
c.tag || c.deck || c.notetype || c.config c.tag || c.deck || c.notetype || c.config
} }
pub fn requires_editor_redraw(&self) -> bool { pub fn requires_note_text_redraw(&self) -> bool {
let c = &self.changes; let c = &self.changes;
c.note || c.notetype c.note || c.notetype
} }
pub fn requires_reviewer_redraw(&self) -> bool { pub fn requires_study_queue_rebuild(&self) -> bool {
let c = &self.changes; let c = &self.changes;
c.card
|| (c.deck && self.op != Op::ExpandCollapse)
|| (c.config && matches!(self.op, Op::SetCurrentDeck | Op::UpdatePreferences))
|| c.deck_config
|| c.note
|| c.notetype
}
/// Internal; allows us to avoid rebuilding queues after AnswerCard,
/// and a few other ops as an optimization.
pub(crate) fn requires_study_queue_rebuild(&self) -> bool {
let c = &self.changes;
if self.op == Op::AnswerCard {
return false;
}
c.card c.card
|| (c.deck && self.op != Op::ExpandCollapse) || (c.deck && self.op != Op::ExpandCollapse)
|| (c.config && matches!(self.op, Op::SetCurrentDeck | Op::UpdatePreferences)) || (c.config && matches!(self.op, Op::SetCurrentDeck | Op::UpdatePreferences))

View File

@ -166,7 +166,7 @@ impl Collection {
} }
pub(crate) fn maybe_clear_study_queues_after_op(&mut self, op: &OpChanges) { pub(crate) fn maybe_clear_study_queues_after_op(&mut self, op: &OpChanges) {
if op.requires_study_queue_rebuild() { if op.op != Op::AnswerCard && op.requires_study_queue_rebuild() {
self.state.card_queues = None; self.state.card_queues = None;
} }
} }