Modern Apps git

← Modern-Apps.git

notes: markdown doesn't soft-wrap

Commit
ceae1f4265d9b3847959dd8a665e64dc361f3be2
Author
Vayun Mathur <[email protected]>
When
2026-04-28 03:02 UTC (7 months ago)
Parents
12b6069

Diff

library/src/main/java/com/vayunmathur/library/util/Markdown.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/Markdown.kt b/library/src/main/java/com/vayunmathur/library/util/Markdown.ktindex aff53b6c9d..34c8e16e9e 100644--- a/library/src/main/java/com/vayunmathur/library/util/Markdown.kt+++ b/library/src/main/java/com/vayunmathur/library/util/Markdown.kt@@ -20,8 +20,14 @@ import androidx.compose.ui.unit.sp  * @param mdtext The raw markdown text.  * @param showMarkers If false, the formatting symbols (#, *, etc.) are hidden and occupy no space.  * @param process If true, the text is preprocessed for newline rules and list normalization.+ * @param softWrap If true, single newlines in regular text blocks are merged into a single line.  */-fun parseMarkdown(mdtext: String, showMarkers: Boolean = true, process: Boolean = true): AnnotatedString {+fun parseMarkdown(+    mdtext: String,+    showMarkers: Boolean = true,+    process: Boolean = true,+    softWrap: Boolean = true+): AnnotatedString {     // 1. Preprocess text for newline rules and list normalization     val processedText = if (process) {         val lines = mdtext.lines()@@ -59,18 +65,20 @@ fun parseMarkdown(mdtext: String, showMarkers: Boolean = true, process: Boolean                 } else {                     // Regular text: Rule: 1 newline becomes 0 newlines only when both lines are not headers or bullets                     var merged = line.trim()-                    while (i + 1 < lines.size && lines[i + 1].isNotBlank()) {-                        val nextLine = lines[i + 1]-                        val nextTrimmed = nextLine.trimStart()-                        val nextListMatch =-                            Regex("^(\\s*)([•*+-]|\\d+[.)])(\\s+.*)").matchEntire(nextLine)-                        val isNextSpecial =-                            nextTrimmed.startsWith("#") || nextTrimmed.startsWith(">") || nextListMatch != null--                        if (isNextSpecial) break // Newline preserved if next line is special--                        merged += " " + nextLine.trim()-                        i+++                    if (softWrap) {+                        while (i + 1 < lines.size && lines[i + 1].isNotBlank()) {+                            val nextLine = lines[i + 1]+                            val nextTrimmed = nextLine.trimStart()+                            val nextListMatch =+                                Regex("^(\\s*)([•*+-]|\\d+[.)])(\\s+.*)").matchEntire(nextLine)+                            val isNextSpecial =+                                nextTrimmed.startsWith("#") || nextTrimmed.startsWith(">") || nextListMatch != null++                            if (isNextSpecial) break // Newline preserved if next line is special++                            merged += " " + nextLine.trim()+                            i+++                        }                     }                     append(merged + "\n")                 }
notes/src/main/java/com/vayunmathur/notes/ui/NotePage.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotePage.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotePage.ktindex b85601b432..63200f280a 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotePage.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotePage.kt@@ -108,7 +108,7 @@ fun NotePage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, noteI                 var value by remember(note.id) {                     mutableStateOf(                         TextFieldValue(-                            parseMarkdown(note.content, process = false)+                            parseMarkdown(note.content, process = false, softWrap = false)                         )                     )                 }@@ -117,7 +117,8 @@ fun NotePage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, noteI                         TextFieldValue(                             parseMarkdown(                                 note.content,-                                false+                                false,+                                softWrap = false                             )                         )                     }@@ -126,7 +127,7 @@ fun NotePage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, noteI                     if (isEditing) value else noMarkers,                     {                         note = note.copy(content = it.text)-                        value = it.copy(annotatedString = parseMarkdown(it.text, process = false))+                        value = it.copy(annotatedString = parseMarkdown(it.text, process = false, softWrap = false))                     },                     Modifier.fillMaxSize(),                     readOnly = !isEditing,