From d67d54db2431be893741e2184249e1fe2b7703aa Mon Sep 17 00:00:00 2001 From: Hasinjato Date: Thu, 23 Jul 2026 14:58:37 +0300 Subject: [PATCH] Fix! keep block template when attaching on hairpin marker --- .../kotlin/mg/dot/feufaro/solfa/Solfa.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt index b39fd0a..dc6c60a 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -899,11 +899,13 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository return finalResult } - - /* Set Pending Hairpin */ - when (initMarkerValue) { - "\${>}", "\${<}" -> sharedScreenModel.setPendingHairPin(true, targetPointer) - "\${=}" -> sharedScreenModel.setPendingHairPin(false) + when { + initMarkerValue.contains("\${>}") || initMarkerValue.contains("\${<}") -> { + sharedScreenModel.setPendingHairPin(true, targetPointer) + } + initMarkerValue.contains("\${=}") -> { + sharedScreenModel.setPendingHairPin(false) + } } val notesByVoice = editState.notesByVoice @@ -1014,15 +1016,20 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository if (oldHadOpen && !newHasOpen) { dropNextCloseParenthesis = true } - var adjustedTemplate = newTemplate - if (newTemplate.endsWith(")")) { - val remainingText = body.substring(i).trimStart { it in separators } - if (remainingText.startsWith(")")) { - adjustedTemplate = newTemplate.dropLast(1) - } - } - val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + adjustedTemplate + val bodyContent = if (newTemplate.isNotEmpty() && anyNoteModified) { + var adjusted = newTemplate + if (newTemplate.endsWith(")")) { + val remainingText = body.substring(i).trimStart { it in separators } + if (remainingText.startsWith(")")) { + adjusted = newTemplate.dropLast(1) + } + } + adjusted + } else { + oldCleaned + } + val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + bodyContent var cleanedProcessed = rawProcessed while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) {