Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object MarginAnnotationParser {

for (block in explicitBlocks) {
val tag = block.tag ?: continue
if (canvasTags.any { (canvasTag, _) -> canvasTag == tag }) {
if (canvasTags.isEmpty() || canvasTags.any { (canvasTag, _) -> canvasTag == tag }) {
annotationMap[tag] = block.annotationText
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,51 @@ class SpinnerWidget(

override fun processAttributes(context: XmlContext, id: String, attrs: Map<String, String>): Map<String, String> {
val processed = mutableMapOf<String, String>()
val rawEntries = attrs[AttributeKey.ENTRIES.xmlName]
?: attrs[AttributeKey.TEXT.xmlName]
?: box.text.takeIf { it.isMeaningfulDropdownText() }

when {
rawEntries == null -> Unit
rawEntries.trimStart().startsWith("@") -> {
processed[AttributeKey.ENTRIES.xmlName] = rawEntries.trim().escapeXmlAttr()
}
else -> rawEntries
.toSpinnerEntries()
.takeIf { it.isNotEmpty() }
?.let { items ->
val arrayName = "${id}_array"
context.stringArrays[arrayName] = items
processed[AttributeKey.ENTRIES.xmlName] = "@array/$arrayName"
}
}

attrs.forEach { (key, value) ->
if (key == AttributeKey.ENTRIES.xmlName && !value.startsWith("@")) {
val arrayName = "${id}_array"
val items = value.split(",").map { it.trim() }.filter { it.isNotEmpty() }

context.stringArrays[arrayName] = items
processed[key] = "@array/$arrayName"
} else {
processed[key] = value.escapeXmlAttr()
when {
key == AttributeKey.ENTRIES.xmlName || key == AttributeKey.TEXT.xmlName -> Unit
else -> processed[key] = value.escapeXmlAttr()
}
}
return processed
}

private fun String.toSpinnerEntries(): List<String> {
return removeTrailingDropdownGlyph()
.split(Regex("\\s*[,;|/\\n]+\\s*"))
.map { it.trim() }
.filter { it.isNotEmpty() }
}

private fun String.removeTrailingDropdownGlyph(): String {
return trim()
.replace(Regex("\\s*[▼▽▾▿⌄˅∨]$|\\s+[vV]$"), "")
.trim()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

private fun String.isMeaningfulDropdownText(): Boolean {
val cleaned = removeTrailingDropdownGlyph()
return cleaned.isNotBlank() && !cleaned.equals("dropdown", ignoreCase = true)
}
}

class TextBasedWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ object MetadataDetector {
)

private val xmlAttributeRegex = Regex("""\b(?:android|app|tools):[a-zA-Z_]+\b""")
private val assignmentRegex = Regex("""\b[a-zA-Z_]+(?:[:=])[^\s]+""")

fun isCanvasMetadata(text: String): Boolean {
val lowerText = text.lowercase()
if (lowerText.isBlank()) return false
if (metadataSnippets.any { snippet -> lowerText.contains(snippet) }) return true
if (xmlAttributeRegex.containsMatchIn(lowerText)) return true
if (metadataKeywords.any { keyword -> lowerText.contains(keyword) }) return true

val assignmentCount = assignmentRegex.findAll(lowerText).count()
return assignmentCount >= 2
return false
}

fun isMetadataLabel(label: String): Boolean {
Expand Down
Loading