Modern Apps git

← Modern-Apps.git

code: add find/replace and autocomplete to the experimental editor engine

Commit
7df8939824a39ab38385ebafc98e0b2f6572c59b
Author
Vayun Mathur <[email protected]>
When
2026-08-07 02:49 UTC (4 months ago)
Parents
723dae6

Diff

code/src/main/java/com/vayunmathur/code/ui/CodeEditor.kt
diff --git a/code/src/main/java/com/vayunmathur/code/ui/CodeEditor.kt b/code/src/main/java/com/vayunmathur/code/ui/CodeEditor.ktindex a4af7dbb15..d71c382f83 100644--- a/code/src/main/java/com/vayunmathur/code/ui/CodeEditor.kt+++ b/code/src/main/java/com/vayunmathur/code/ui/CodeEditor.kt@@ -1,21 +1,12 @@ package com.vayunmathur.code.ui -import androidx.compose.ui.res.stringResource-import com.vayunmathur.code.R-import androidx.compose.foundation.background-import androidx.compose.foundation.clickable import androidx.compose.foundation.horizontalScroll-import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.BasicTextField@@ -26,7 +17,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.SolidColor@@ -36,25 +26,16 @@ import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp-import androidx.compose.ui.window.Popup-import androidx.compose.ui.window.PopupProperties import com.vayunmathur.code.syntax.SyntaxTransformation import com.vayunmathur.code.syntax.rememberSyntaxColors import com.vayunmathur.code.util.CodeActions import com.vayunmathur.code.util.Completion import com.vayunmathur.code.util.TabUiState import com.vayunmathur.library.ui.HorizontalDivider-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconChevronRight-import com.vayunmathur.library.ui.IconClose-import com.vayunmathur.library.ui.IconKeyboardArrowUp import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import kotlin.math.roundToInt  /**@@ -95,25 +76,7 @@ fun CodeEditor(         !useRegex || query.isEmpty() || runCatching { Regex(query) }.isSuccess     }     val matches = remember(text, query, caseSensitive, useRegex) {-        if (query.isEmpty()) {-            emptyList()-        } else if (useRegex) {-            runCatching {-                val options = if (caseSensitive) emptySet() else setOf(RegexOption.IGNORE_CASE)-                Regex(query, options).findAll(text)-                    .map { it.range }-                    .filter { !it.isEmpty() }-                    .toList()-            }.getOrDefault(emptyList())-        } else {-            val found = ArrayList<IntRange>()-            var i = text.indexOf(query, 0, ignoreCase = !caseSensitive)-            while (i >= 0) {-                found.add(i until i + query.length)-                i = text.indexOf(query, i + query.length, ignoreCase = !caseSensitive)-            }-            found-        }+        findMatchRanges(text, query, caseSensitive, useRegex)     }      LaunchedEffect(matches.size) {@@ -203,12 +166,15 @@ fun CodeEditor(                 )                 val layout = layoutResult                 if (showCompletions && completions.isNotEmpty() && caret >= 0 && layout != null) {+                    val padPx = with(LocalDensity.current) { 8.dp.roundToPx() }+                    val safeCaret = caret.coerceIn(0, layout.layoutInput.text.length)+                    val cursorRect = layout.getCursorRect(safeCaret)+                    val x = (cursorRect.left - horizontalScroll.value + padPx).roundToInt()+                    val y = (cursorRect.bottom - verticalScroll.value).roundToInt()                     CompletionPopup(                         completions = completions,-                        layout = layout,-                        caret = caret,-                        hScroll = horizontalScroll.value,-                        vScroll = verticalScroll.value,+                        offsetX = x,+                        offsetY = y,                         onAccept = { actions.acceptCompletion(it) },                         onDismiss = { actions.dismissCompletions() },                     )@@ -218,54 +184,6 @@ fun CodeEditor(     } } -/**- * The autocomplete list, anchored just below the caret. Positioned with [TextLayoutResult]'s- * cursor rect (offset mapping is identity, so no mapping is needed) minus the editor's scroll.- * The popup is non-focusable so typing keeps driving the text field and the list.- */-@Composable-private fun CompletionPopup(-    completions: List<Completion>,-    layout: TextLayoutResult,-    caret: Int,-    hScroll: Int,-    vScroll: Int,-    onAccept: (Completion) -> Unit,-    onDismiss: () -> Unit,-) {-    val padPx = with(LocalDensity.current) { 8.dp.roundToPx() }-    val safeCaret = caret.coerceIn(0, layout.layoutInput.text.length)-    val cursorRect = layout.getCursorRect(safeCaret)-    val x = (cursorRect.left - hScroll + padPx).roundToInt()-    val y = (cursorRect.bottom - vScroll).roundToInt()-    Popup(-        alignment = Alignment.TopStart,-        offset = IntOffset(x, y),-        onDismissRequest = onDismiss,-        properties = PopupProperties(focusable = false),-    ) {-        Column(-            Modifier-                .width(240.dp)-                .heightIn(max = 200.dp)-                .background(MaterialTheme.colorScheme.surfaceVariant)-                .verticalScroll(rememberScrollState()),-        ) {-            completions.forEach { completion ->-                Text(-                    text = completion.label,-                    modifier = Modifier-                        .fillMaxWidth()-                        .clickable { onAccept(completion) }-                        .padding(horizontal = 12.dp, vertical = 6.dp),-                    style = TextStyle(fontFamily = FontFamily.Monospace),-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                )-            }-        }-    }-}- /**  * The line-number column. Rendered as a single right-aligned [Text] (one number per line) so  * it stays cheap for large files, and sharing [verticalScroll] keeps it locked to the editor.@@ -286,83 +204,3 @@ private fun LineGutter(lineCount: Int, verticalScroll: androidx.compose.foundati         textAlign = TextAlign.Right,     ) }--/** The find/replace bar: two fields, prev/next navigation, a match count and replace actions. */-@Composable-private fun FindBar(-    query: String,-    replacement: String,-    caseSensitive: Boolean,-    useRegex: Boolean,-    regexValid: Boolean,-    matchCount: Int,-    activeMatch: Int,-    onQueryChange: (String) -> Unit,-    onReplacementChange: (String) -> Unit,-    onToggleCase: () -> Unit,-    onToggleRegex: () -> Unit,-    onNext: () -> Unit,-    onPrev: () -> Unit,-    onReplace: () -> Unit,-    onReplaceAll: () -> Unit,-    onClose: () -> Unit,-) {-    Column(Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 4.dp)) {-        Row(verticalAlignment = Alignment.CenterVertically) {-            OutlinedTextField(-                value = query,-                onValueChange = onQueryChange,-                modifier = Modifier.weight(1f),-                placeholder = { Text(stringResource(R.string.find)) },-                singleLine = true,-                isError = !regexValid,-                supportingText = if (!regexValid) {-                    { Text(stringResource(R.string.invalid_regex)) }-                } else {-                    null-                },-            )-            val label = if (matchCount == 0) "0/0" else "${activeMatch + 1}/$matchCount"-            Text(label, modifier = Modifier.padding(horizontal = 8.dp))-            IconButton(onClick = onPrev, enabled = matchCount > 0) { IconKeyboardArrowUp() }-            IconButton(onClick = onNext, enabled = matchCount > 0) { IconChevronRight() }-            IconButton(onClick = onClose) { IconClose() }-        }-        Spacer(Modifier.size(4.dp))-        Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {-            OutlinedTextField(-                value = replacement,-                onValueChange = onReplacementChange,-                modifier = Modifier.weight(1f),-                placeholder = { Text(stringResource(R.string.replace)) },-                singleLine = true,-            )-            TextButton(onClick = onReplace, enabled = matchCount > 0) { Text(stringResource(R.string.replace)) }-            TextButton(onClick = onReplaceAll, enabled = matchCount > 0) { Text(stringResource(R.string.all)) }-        }-        Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {-            ToggleChip(-                label = stringResource(R.string.match_case),-                selected = caseSensitive,-                onClick = onToggleCase,-            )-            ToggleChip(-                label = stringResource(R.string.use_regex),-                selected = useRegex,-                onClick = onToggleRegex,-            )-        }-    }-}--/** A small text toggle that colours itself when active; used for the find-bar options. */-@Composable-private fun ToggleChip(label: String, selected: Boolean, onClick: () -> Unit) {-    TextButton(onClick = onClick) {-        Text(-            label,-            color = if (selected) MaterialTheme.colorScheme.primary-            else MaterialTheme.colorScheme.onSurfaceVariant,-        )-    }-}
code/src/main/java/com/vayunmathur/code/ui/CodeEditorView.kt
diff --git a/code/src/main/java/com/vayunmathur/code/ui/CodeEditorView.kt b/code/src/main/java/com/vayunmathur/code/ui/CodeEditorView.ktindex d8f0f057d1..b1a535f47d 100644--- a/code/src/main/java/com/vayunmathur/code/ui/CodeEditorView.kt+++ b/code/src/main/java/com/vayunmathur/code/ui/CodeEditorView.kt@@ -8,11 +8,15 @@ import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.detectVerticalDragGestures import androidx.compose.foundation.gestures.rememberScrollableState import androidx.compose.foundation.gestures.scrollable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember@@ -46,16 +50,19 @@ import androidx.compose.ui.text.rememberTextMeasurer import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp+import kotlin.math.roundToInt import com.vayunmathur.code.syntax.LanguageSpec import com.vayunmathur.code.syntax.SyntaxColors import com.vayunmathur.code.syntax.rememberSyntaxColors import com.vayunmathur.code.util.CodeActions+import com.vayunmathur.code.util.Completion import com.vayunmathur.code.util.Edit import com.vayunmathur.code.util.EditorDocument import com.vayunmathur.code.util.TabUiState import com.vayunmathur.code.util.computeFoldRegions import com.vayunmathur.code.util.dedentSelection import com.vayunmathur.code.util.indentSelection+import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.MaterialTheme  /**@@ -79,6 +86,11 @@ fun CodeEditorView(     showWhitespace: Boolean = false,     showIndentGuides: Boolean = false,     showMinimap: Boolean = false,+    showFind: Boolean = false,+    onCloseFind: () -> Unit = {},+    initialQuery: String = "",+    completions: List<Completion> = emptyList(),+    showCompletions: Boolean = false,     secondaryPane: Boolean = false,     onValueChangeOverride: ((TextFieldValue) -> Unit)? = null, ) {@@ -156,6 +168,44 @@ fun CodeEditorView(      val emit: (TextFieldValue) -> Unit = onValueChangeOverride ?: actions::onEditorChange +    // ---- Find state (Phase 4): mirrors the classic editor, highlighted in the Canvas below. ----+    var query by remember(tab.name) { mutableStateOf(initialQuery) }+    var replacement by remember(tab.name) { mutableStateOf("") }+    var caseSensitive by remember(tab.name) { mutableStateOf(false) }+    var useRegex by remember(tab.name) { mutableStateOf(false) }+    var activeMatch by remember(tab.name) { mutableStateOf(0) }+    val regexValid = remember(query, useRegex) {+        !useRegex || query.isEmpty() || runCatching { Regex(query) }.isSuccess+    }+    val matches = remember(text, query, caseSensitive, useRegex) {+        findMatchRanges(text, query, caseSensitive, useRegex)+    }+    val highlightMatches = if (showFind) matches else emptyList()+    LaunchedEffect(matches.size) { if (activeMatch >= matches.size) activeMatch = 0 }+    val goTo: (Int) -> Unit = { target ->+        if (matches.isNotEmpty()) {+            val idx = ((target % matches.size) + matches.size) % matches.size+            activeMatch = idx+            val r = matches[idx]+            actions.setSelection(TextRange(r.first, r.last + 1))+        }+    }+    // Keep the active match scrolled into view as the user navigates.+    LaunchedEffect(activeMatch, matches.size) {+        if (showFind && matches.isNotEmpty() && viewport.height > 0) {+            val r = matches[activeMatch.coerceIn(0, matches.size - 1)]+            val row = visibleLines.indexOf(lineOfOffset(lineStarts, r.first))+            if (row >= 0) {+                val top = row * lineHeight+                if (top < scrollY) {+                    scrollY = top+                } else if (top + lineHeight > scrollY + viewport.height) {+                    scrollY = (top - viewport.height + lineHeight).coerceAtLeast(0f)+                }+            }+        }+    }+     fun displayRowToSource(row: Int): Int? = visibleLines.getOrNull(row)      fun offsetAt(x: Float, y: Float): Int {@@ -241,6 +291,23 @@ fun CodeEditorView(                     }                 } +                // Find-match highlight (Phase 4): the active match is drawn more strongly.+                if (highlightMatches.isNotEmpty()) {+                    for ((mi, m) in highlightMatches.withIndex()) {+                        val ms = m.first+                        val me = m.last + 1+                        if (me <= lineStart || ms >= lineStart + lineLen) continue+                        val a = (ms - lineStart).coerceIn(0, lineLen)+                        val b = (me - lineStart).coerceIn(0, lineLen)+                        if (b > a) {+                            val startX = gutterWidth + a * charWidth - scrollX+                            val w = (b - a) * charWidth+                            val matchColor = if (mi == activeMatch) caretColor.copy(alpha = 0.35f) else colors.match+                            drawRect(matchColor, topLeft = Offset(startX, y), size = Size(w, lineHeight))+                        }+                    }+                }+                 if (showIndentGuides) {                     val columns = leadingColumns(lineText, tabWidth)                     var level = tabWidth@@ -293,24 +360,83 @@ fun CodeEditorView(         }     } -    if (showMinimap) {-        Row(modifier.fillMaxSize()) {-            editorCanvas(Modifier.weight(1f).fillMaxHeight())-            Minimap(-                lines = lines,-                lineHeight = lineHeight,-                scrollY = scrollY,-                maxScrollY = maxScrollY,-                viewportHeight = viewport.height.toFloat(),-                totalHeight = totalHeight,-                color = gutterColor.copy(alpha = 0.5f),-                viewportColor = caretColor.copy(alpha = 0.2f),-                onScrollTo = { fraction -> scrollY = (fraction * maxScrollY).coerceIn(0f, maxScrollY) },-                modifier = Modifier.width(56.dp).fillMaxHeight(),+    Column(modifier.fillMaxSize()) {+        if (showFind) {+            FindBar(+                query = query,+                replacement = replacement,+                caseSensitive = caseSensitive,+                useRegex = useRegex,+                regexValid = regexValid,+                matchCount = matches.size,+                activeMatch = activeMatch,+                onQueryChange = { query = it; activeMatch = 0 },+                onReplacementChange = { replacement = it },+                onToggleCase = { caseSensitive = !caseSensitive },+                onToggleRegex = { useRegex = !useRegex; activeMatch = 0 },+                onNext = { goTo(activeMatch + 1) },+                onPrev = { goTo(activeMatch - 1) },+                onReplace = {+                    matches.getOrNull(activeMatch)?.let { range ->+                        if (useRegex) {+                            actions.replaceMatchRegex(range, query, replacement, caseSensitive)+                        } else {+                            actions.replaceRange(range, replacement)+                        }+                    }+                },+                onReplaceAll = {+                    if (useRegex) {+                        actions.replaceAllRegex(query, replacement, caseSensitive)+                    } else {+                        actions.replaceAll(matches, replacement)+                    }+                },+                onClose = onCloseFind,             )+            HorizontalDivider()+        }++        Box(Modifier.weight(1f).fillMaxWidth()) {+            if (showMinimap) {+                Row(Modifier.fillMaxSize()) {+                    editorCanvas(Modifier.weight(1f).fillMaxHeight())+                    Minimap(+                        lines = lines,+                        lineHeight = lineHeight,+                        scrollY = scrollY,+                        maxScrollY = maxScrollY,+                        viewportHeight = viewport.height.toFloat(),+                        totalHeight = totalHeight,+                        color = gutterColor.copy(alpha = 0.5f),+                        viewportColor = caretColor.copy(alpha = 0.2f),+                        onScrollTo = { fraction -> scrollY = (fraction * maxScrollY).coerceIn(0f, maxScrollY) },+                        modifier = Modifier.width(56.dp).fillMaxHeight(),+                    )+                }+            } else {+                editorCanvas(Modifier.fillMaxSize())+            }++            // Autocomplete popup (Phase 4), anchored at the caret in Canvas coordinates.+            val caretOffset = value.selection.start+            if (showCompletions && completions.isNotEmpty() && value.selection.collapsed) {+                val src = lineOfOffset(lineStarts, caretOffset)+                val row = visibleLines.indexOf(src)+                if (row >= 0) {+                    val col = caretOffset - lineStarts[src]+                    val px = (gutterWidth + col * charWidth - scrollX).roundToInt()+                    val py = (row * lineHeight - scrollY + lineHeight).roundToInt()+                    CompletionPopup(+                        completions = completions,+                        offsetX = px,+                        offsetY = py,+                        onAccept = { actions.acceptCompletion(it) },+                        onDismiss = { actions.dismissCompletions() },+                    )+                }+            }         }-    } else {-        editorCanvas(modifier.fillMaxSize())     } } 
code/src/main/java/com/vayunmathur/code/ui/EditorChrome.kt
diff --git a/code/src/main/java/com/vayunmathur/code/ui/EditorChrome.kt b/code/src/main/java/com/vayunmathur/code/ui/EditorChrome.ktnew file mode 100644index 0000000000..82c063b35c--- /dev/null+++ b/code/src/main/java/com/vayunmathur/code/ui/EditorChrome.kt@@ -0,0 +1,188 @@+package com.vayunmathur.code.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.heightIn+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.TextStyle+import androidx.compose.ui.text.font.FontFamily+import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.dp+import androidx.compose.ui.window.Popup+import androidx.compose.ui.window.PopupProperties+import com.vayunmathur.code.R+import com.vayunmathur.code.util.Completion+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconChevronRight+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.IconKeyboardArrowUp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton++/**+ * Shared editor chrome used by both the classic [CodeEditor] and the experimental+ * [CodeEditorView]: the find/replace bar, the autocomplete popup, and the pure match finder+ * that backs both editors' search highlighting.+ */++/**+ * All (non-empty) match ranges of [query] in [text]. When [useRegex] is set an invalid pattern+ * yields no matches rather than throwing. Ranges are end-inclusive (`first..last`).+ */+fun findMatchRanges(+    text: String,+    query: String,+    caseSensitive: Boolean,+    useRegex: Boolean,+): List<IntRange> {+    if (query.isEmpty()) return emptyList()+    return if (useRegex) {+        runCatching {+            val options = if (caseSensitive) emptySet() else setOf(RegexOption.IGNORE_CASE)+            Regex(query, options).findAll(text).map { it.range }.filter { !it.isEmpty() }.toList()+        }.getOrDefault(emptyList())+    } else {+        val found = ArrayList<IntRange>()+        var i = text.indexOf(query, 0, ignoreCase = !caseSensitive)+        while (i >= 0) {+            found.add(i until i + query.length)+            i = text.indexOf(query, i + query.length, ignoreCase = !caseSensitive)+        }+        found+    }+}++/**+ * The autocomplete list, anchored at ([offsetX], [offsetY]) pixels within the editor box (the+ * caller supplies the caret position). Non-focusable so typing keeps driving the editor.+ */+@Composable+fun CompletionPopup(+    completions: List<Completion>,+    offsetX: Int,+    offsetY: Int,+    onAccept: (Completion) -> Unit,+    onDismiss: () -> Unit,+) {+    Popup(+        alignment = Alignment.TopStart,+        offset = IntOffset(offsetX, offsetY),+        onDismissRequest = onDismiss,+        properties = PopupProperties(focusable = false),+    ) {+        Column(+            Modifier+                .width(240.dp)+                .heightIn(max = 200.dp)+                .background(MaterialTheme.colorScheme.surfaceVariant)+                .verticalScroll(rememberScrollState()),+        ) {+            completions.forEach { completion ->+                Text(+                    text = completion.label,+                    modifier = Modifier+                        .fillMaxWidth()+                        .clickable { onAccept(completion) }+                        .padding(horizontal = 12.dp, vertical = 6.dp),+                    style = TextStyle(fontFamily = FontFamily.Monospace),+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                )+            }+        }+    }+}++/** The find/replace bar: two fields, prev/next navigation, a match count and replace actions. */+@Composable+fun FindBar(+    query: String,+    replacement: String,+    caseSensitive: Boolean,+    useRegex: Boolean,+    regexValid: Boolean,+    matchCount: Int,+    activeMatch: Int,+    onQueryChange: (String) -> Unit,+    onReplacementChange: (String) -> Unit,+    onToggleCase: () -> Unit,+    onToggleRegex: () -> Unit,+    onNext: () -> Unit,+    onPrev: () -> Unit,+    onReplace: () -> Unit,+    onReplaceAll: () -> Unit,+    onClose: () -> Unit,+) {+    Column(Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 4.dp)) {+        Row(verticalAlignment = Alignment.CenterVertically) {+            OutlinedTextField(+                value = query,+                onValueChange = onQueryChange,+                modifier = Modifier.weight(1f),+                placeholder = { Text(stringResource(R.string.find)) },+                singleLine = true,+                isError = !regexValid,+                supportingText = if (!regexValid) {+                    { Text(stringResource(R.string.invalid_regex)) }+                } else {+                    null+                },+            )+            val label = if (matchCount == 0) "0/0" else "${activeMatch + 1}/$matchCount"+            Text(label, modifier = Modifier.padding(horizontal = 8.dp))+            IconButton(onClick = onPrev, enabled = matchCount > 0) { IconKeyboardArrowUp() }+            IconButton(onClick = onNext, enabled = matchCount > 0) { IconChevronRight() }+            IconButton(onClick = onClose) { IconClose() }+        }+        Spacer(Modifier.size(4.dp))+        Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {+            OutlinedTextField(+                value = replacement,+                onValueChange = onReplacementChange,+                modifier = Modifier.weight(1f),+                placeholder = { Text(stringResource(R.string.replace)) },+                singleLine = true,+            )+            TextButton(onClick = onReplace, enabled = matchCount > 0) { Text(stringResource(R.string.replace)) }+            TextButton(onClick = onReplaceAll, enabled = matchCount > 0) { Text(stringResource(R.string.all)) }+        }+        Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+            ToggleChip(+                label = stringResource(R.string.match_case),+                selected = caseSensitive,+                onClick = onToggleCase,+            )+            ToggleChip(+                label = stringResource(R.string.use_regex),+                selected = useRegex,+                onClick = onToggleRegex,+            )+        }+    }+}++/** A small text toggle that colours itself when active; used for the find-bar options. */+@Composable+private fun ToggleChip(label: String, selected: Boolean, onClick: () -> Unit) {+    TextButton(onClick = onClick) {+        Text(+            label,+            color = if (selected) MaterialTheme.colorScheme.primary+            else MaterialTheme.colorScheme.onSurfaceVariant,+        )+    }+}
code/src/main/java/com/vayunmathur/code/ui/EditorScreen.kt
diff --git a/code/src/main/java/com/vayunmathur/code/ui/EditorScreen.kt b/code/src/main/java/com/vayunmathur/code/ui/EditorScreen.ktindex 96410fae6f..68feab46ec 100644--- a/code/src/main/java/com/vayunmathur/code/ui/EditorScreen.kt+++ b/code/src/main/java/com/vayunmathur/code/ui/EditorScreen.kt@@ -273,6 +273,11 @@ fun EditorScreen(                                 showWhitespace = state.showWhitespace,                                 showIndentGuides = state.showIndentGuides,                                 showMinimap = state.showMinimap,+                                showFind = showFind,+                                onCloseFind = { showFind = false },+                                initialQuery = initialFind.orEmpty(),+                                completions = state.completions,+                                showCompletions = state.showCompletions,                             )                         } else {                             CodeEditor(