Modern Apps git

← Modern-Apps.git

web: slimmer omnibox with select-all on focus

Commit
4c8568fce404fb295c79506c5208da116467d4cc
Author
vayun-mathur <[email protected]>
When
2026-09-29 23:25 UTC (2 months ago)
Parents
0d701a1

Diff

web/src/main/java/com/vayunmathur/web/ui/BrowserChrome.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserChrome.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserChrome.ktindex 752b16de84..fe16047e64 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserChrome.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserChrome.kt@@ -181,12 +181,14 @@ private fun DisplayOnlyAddressPill(     modifier: Modifier = Modifier, ) {     // Now matches CommonSearchBar visually: OutlinedTextField 28dp rounded, search icon, same padding.+    // bodySmall keeps the bar slim so more of the URL fits horizontally.     Box(modifier = modifier) {         OutlinedTextField(             value = fullUrl,             onValueChange = {},             readOnly = true,-            placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+            textStyle = MaterialTheme.typography.bodySmall,+            placeholder = { Text(stringResource(R.string.search_or_enter_address), style = MaterialTheme.typography.bodySmall) },             leadingIcon = { IconSearch() },             singleLine = true,             shape = RoundedCornerShape(28.dp),
web/src/main/java/com/vayunmathur/web/ui/BrowserOmniboxEditor.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserOmniboxEditor.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserOmniboxEditor.ktindex 10ee6f1649..9dcb1f974f 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserOmniboxEditor.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserOmniboxEditor.kt@@ -10,13 +10,19 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable+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.FocusRequester import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.ImeAction+import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.DesktopMaxWidthContainer@@ -25,6 +31,7 @@ import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconSearch+import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Scaffold import com.vayunmathur.library.ui.Surface@@ -61,24 +68,42 @@ internal fun OmniboxEditor(      BoxWithConstraints(Modifier.fillMaxSize()) {         val effectiveAtBottom = viewModel.searchBarAtBottom && maxHeight >= 480.dp+        // TextFieldValue so entering the field selects everything: the first+        // keystroke replaces the URL instead of appending to it.+        var fieldValue by remember(viewModel.searchDraft) {+            mutableStateOf(TextFieldValue(viewModel.searchDraft, TextRange(viewModel.searchDraft.length)))+        }         val omniboxField: @Composable (Modifier) -> Unit = { fieldModifier ->             OutlinedTextField(-                value = viewModel.searchDraft,-                onValueChange = { viewModel.searchDraft = it },-                modifier = fieldModifier.focusRequester(searchFocusRequester),-                placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+                value = fieldValue,+                onValueChange = {+                    fieldValue = it+                    viewModel.searchDraft = it.text+                },+                modifier = fieldModifier+                    .focusRequester(searchFocusRequester)+                    .onFocusChanged { focus ->+                        if (focus.isFocused) {+                            fieldValue = fieldValue.copy(selection = TextRange(0, fieldValue.text.length))+                        }+                    },+                textStyle = MaterialTheme.typography.bodySmall,+                placeholder = { Text(stringResource(R.string.search_or_enter_address), style = MaterialTheme.typography.bodySmall) },                 leadingIcon = { IconSearch() },-                trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {+                trailingIcon = if (fieldValue.text.isNotEmpty()) {                     {-                        IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }+                        IconButton(onClick = {+                            fieldValue = TextFieldValue("")+                            viewModel.searchDraft = ""+                        }) { IconClose() }                     }                 } else null,                 shape = RoundedCornerShape(28.dp),                 singleLine = true,                 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),                 keyboardActions = KeyboardActions(onSearch = {-                    if (viewModel.searchDraft.isNotBlank()) {-                        onNavigate(viewModel.searchDraft)+                    if (fieldValue.text.isNotBlank()) {+                        onNavigate(fieldValue.text)                     }                 })             )