mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-06 13:53:02 -05:00
fix: Make search escape regex, so '.' and similar behave properly. (#2263)
This commit is contained in:
@@ -126,11 +126,13 @@ class LogSearchManager {
|
||||
}
|
||||
return filteredLogs.flatMapIndexed { logIndex, log ->
|
||||
searchText.split(" ").flatMap { term ->
|
||||
val messageMatches = term.toRegex(RegexOption.IGNORE_CASE).findAll(log.logMessage)
|
||||
val escapedTerm = Regex.escape(term)
|
||||
val regex = escapedTerm.toRegex(RegexOption.IGNORE_CASE)
|
||||
val messageMatches = regex.findAll(log.logMessage)
|
||||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "message") }
|
||||
val typeMatches = term.toRegex(RegexOption.IGNORE_CASE).findAll(log.messageType)
|
||||
val typeMatches = regex.findAll(log.messageType)
|
||||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "type") }
|
||||
val dateMatches = term.toRegex(RegexOption.IGNORE_CASE).findAll(log.formattedReceivedDate)
|
||||
val dateMatches = regex.findAll(log.formattedReceivedDate)
|
||||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "date") }
|
||||
messageMatches + typeMatches + dateMatches
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ private fun rememberAnnotatedString(
|
||||
append(text)
|
||||
if (searchText.isNotEmpty()) {
|
||||
searchText.split(" ").forEach { term ->
|
||||
term.toRegex(RegexOption.IGNORE_CASE).findAll(text).forEach { match ->
|
||||
Regex(Regex.escape(term), RegexOption.IGNORE_CASE).findAll(text).forEach { match ->
|
||||
addStyle(
|
||||
style = highlightStyle,
|
||||
start = match.range.first,
|
||||
@@ -339,7 +339,7 @@ private fun rememberAnnotatedLogMessage(log: UiMeshLog, searchText: String): Ann
|
||||
// Add search highlight annotations
|
||||
if (searchText.isNotEmpty()) {
|
||||
searchText.split(" ").forEach { term ->
|
||||
term.toRegex(RegexOption.IGNORE_CASE).findAll(log.logMessage).forEach { match ->
|
||||
Regex(Regex.escape(term), RegexOption.IGNORE_CASE).findAll(log.logMessage).forEach { match ->
|
||||
addStyle(
|
||||
style = highlightStyle,
|
||||
start = match.range.first,
|
||||
|
||||
Reference in New Issue
Block a user