From 502ce7f4ebf058f411f822391f501ad15d113548 Mon Sep 17 00:00:00 2001 From: SanjaySargam Date: Sat, 1 Jun 2024 12:45:23 +0530 Subject: [PATCH] load fragment when performing action on cards This commit updates the previewer when addition, deletion, renaming of cards. --- .../main/java/com/ichi2/anki/CardTemplateEditor.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt index ceacd44dcf..1399e36a84 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardTemplateEditor.kt @@ -570,6 +570,8 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener { // update the tab templateEditor.viewPager.adapter!!.notifyDataSetChanged() + // Update the tab name in previewer + templateEditor.loadTemplatePreviewerFragmentIfFragmented() } } @@ -1028,12 +1030,21 @@ open class CardTemplateEditor : AnkiActivity(), DeckSelectionListener { /** * Execute an action on the schema, asking the user to confirm that a full sync is ok + * If [schemaChangingAction] is successfully executed, then the template is reloaded. + * + * This method is always useful because all calls to executeWithSyncCheck may need to refresh the previewer. + * Due to conditional generation (e.g., {{#c5}}foo{{/c5}} which is non-empty only if it's the 5th card and is + * empty otherwise), it's important to reload the template. This is particularly useful for cloze types, + * where a card can move from the 5th to the 6th position due to adding an extra card type, causing content + * to change or be deleted. + * * @param schemaChangingAction The action to execute (adding / removing card) */ private fun executeWithSyncCheck(schemaChangingAction: Runnable) { try { templateEditor.getColUnsafe.modSchema() schemaChangingAction.run() + templateEditor.loadTemplatePreviewerFragmentIfFragmented() } catch (e: ConfirmModSchemaException) { e.log() val d = ConfirmationDialog()