@@ -1604,12 +1604,47 @@ class NoteEditorFragment :
16041604 @NeedsTest(" cards with a cloze notetype but no cloze in fields are previewed as empty card" )
16051605 @NeedsTest(" clozes that don't start at '1' are correctly displayed" )
16061606 suspend fun performPreview () {
1607+ val fields = prepareNoteFields()
1608+ val tags = selectedTags ? : mutableListOf ()
1609+
1610+ val ord = determineCardOrdinal(fields)
1611+
1612+ val args =
1613+ TemplatePreviewerArguments (
1614+ notetypeFile = NotetypeFile (requireContext(), editorNote!! .notetype),
1615+ fields = fields,
1616+ tags = tags,
1617+ id = editorNote!! .id,
1618+ ord = ord,
1619+ fillEmpty = false ,
1620+ )
1621+ val intent = TemplatePreviewerPage .getIntent(requireContext(), args)
1622+ startActivity(intent)
1623+ }
1624+
1625+ /* *
1626+ * Prepares the note fields for the previewer by converting them to the appropriate format.
1627+ *
1628+ * @return A list of field values properly formatted for display
1629+ */
1630+ fun prepareNoteFields (): MutableList <String > {
16071631 val convertNewlines = shouldReplaceNewlines()
16081632
16091633 fun String?.toFieldText (): String = NoteService .convertToHtmlNewline(this .toString(), convertNewlines)
1610- val fields = editFields?.mapTo(mutableListOf ()) { it.fieldText.toFieldText() } ? : mutableListOf ()
1611- val tags = selectedTags ? : mutableListOf ()
16121634
1635+ return editFields?.mapTo(mutableListOf ()) { it.fieldText.toFieldText() } ? : mutableListOf ()
1636+ }
1637+
1638+ /* *
1639+ * Determines the appropriate card ordinal (template position) to display in the previewer
1640+ *
1641+ * For cloze notes, it identifies the first cloze number present in the fields.
1642+ * For standard notes, it uses the currently edited card ordinal if available.
1643+ *
1644+ * @param fields The processed note fields
1645+ * @return The ordinal (position) of the card template to display
1646+ */
1647+ suspend fun determineCardOrdinal (fields : MutableList <String >): Int {
16131648 val ord =
16141649 if (editorNote!! .notetype.isCloze) {
16151650 val tempNote = withCol { Note .fromNotetypeId(this @withCol, editorNote!! .notetype.id) }
@@ -1623,18 +1658,7 @@ class NoteEditorFragment :
16231658 } else {
16241659 currentEditedCard?.ord ? : 0
16251660 }
1626-
1627- val args =
1628- TemplatePreviewerArguments (
1629- notetypeFile = NotetypeFile (requireContext(), editorNote!! .notetype),
1630- fields = fields,
1631- tags = tags,
1632- id = editorNote!! .id,
1633- ord = ord,
1634- fillEmpty = false ,
1635- )
1636- val intent = TemplatePreviewerPage .getIntent(requireContext(), args)
1637- startActivity(intent)
1661+ return ord
16381662 }
16391663
16401664 private fun setTags (tags : Array <String >) {
0 commit comments