Modern Apps git

← Modern-Apps.git

passwords: IME Send + trailing add icon for website field (#949)

Commit
8eb187ecd817b41663fda5e960ee550f176b4a26
Author
Vayun Mathur <[email protected]>
When
2026-12-02 02:19 UTC (4 days ago)
Parents
23da3be
Follow-up to the #949 fix. The website field's keyboard action
was ImeAction.Done, which reads as finishing the form rather
than adding the typed website, and Save silently committed the
field's pending text.

The field now uses ImeAction.Send (Compose has no dedicated Add
IME action; Send is the submit-the-content action) wired through
KeyboardActions(onSend), and gains a trailing IconButton holding
the manifest-generated IconAdd (library/ui/icons.tsv already
lists IconAdd, so no manifest change was needed). Both paths go
through the existing withPendingWebsite validation, so an
implausible value still shows the inline error and is kept.

Save no longer calls addWebsiteFromInput: pending website text
is added only explicitly, via the IME action or the + icon.

Tests pin the semantics ImeAction value, that Save saves without
adding pending (valid or implausible) text, that tapping the +
icon adds the field content, and that an implausible value via
the + icon errors without adding.

Verified: :passwords:testDevUnitTest green (336 tests, 0
failures). :passwords:lint and :passwords:lintVitalRelease
report the same 9 pre-existing errors in untouched files
(KdbxSyncSection.kt, PasskeyPage.kt, Route.kt); no lint
findings in any touched file.

Diff

passwords/AGENTS.md
diff --git a/passwords/AGENTS.md b/passwords/AGENTS.mdindex 8a55dd6f99..e5854dcb7e 100644--- a/passwords/AGENTS.md+++ b/passwords/AGENTS.md@@ -44,7 +44,7 @@ _Install: ./install passwords (dev by default)._ - com/vayunmathur/passwords/domain/Cbor.kt - com/vayunmathur/passwords/domain/ImportSource.kt - com/vayunmathur/passwords/domain/PasskeyLink.kt-- com/vayunmathur/passwords/domain/WebsiteInput.kt — pending-website merge/validation for the edit form (Save and IME Done both commit through it)+- com/vayunmathur/passwords/domain/WebsiteInput.kt — pending-website merge/validation for the edit form (the IME Send action and the trailing + icon commit through it; Save does not) ### platform/ — ViewModel, autofill, passkeys, backup - com/vayunmathur/passwords/platform/PasswordsViewModel.kt - com/vayunmathur/passwords/platform/PasswordsUiContract.kt
passwords/src/main/java/com/vayunmathur/passwords/domain/WebsiteInput.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/domain/WebsiteInput.kt b/passwords/src/main/java/com/vayunmathur/passwords/domain/WebsiteInput.ktindex 4f2c820c76..6e10655d71 100644--- a/passwords/src/main/java/com/vayunmathur/passwords/domain/WebsiteInput.kt+++ b/passwords/src/main/java/com/vayunmathur/passwords/domain/WebsiteInput.kt@@ -14,8 +14,9 @@ sealed interface PendingWebsite { /**  * Merges [rawInput] (the website field's not-yet-committed text) into this draft.  *- * The field keeps its text in local UI state until it is committed, so every exit- * from the editor — IME Done and Save alike — must go through here. Accepting is+ * The field keeps its text in local UI state until it is committed, so the+ * explicit add actions — the IME Send action and the field's trailing + icon —+ * must go through here; Save deliberately does not commit pending text. Accepting is  * deliberately broad: a scheme-less host such as `example.com` is a valid website  * (the detail screen adds `https://` when opening it and [DomainMatch] strips the  * scheme when matching), and a full URL is stored as typed. Only text that cannot
passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordEditScreen.kt
diff --git a/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordEditScreen.kt b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordEditScreen.ktindex 418e6bc7a5..9e47d31e94 100644--- a/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordEditScreen.kt+++ b/passwords/src/main/java/com/vayunmathur/passwords/ui/PasswordEditScreen.kt@@ -24,6 +24,8 @@ import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.InputChip import com.vayunmathur.library.ui.LabeledTextField@@ -97,12 +99,9 @@ fun PasswordEditScreen(                     saveError = nameRequired                     return@Button                 }-                // The website field's text lives outside the draft until committed;-                // commit it here too, or typing a website and tapping Save would-                // silently drop it. An implausible website aborts the save with a-                // visible error instead.-                if (!addWebsiteFromInput()) return@Button-                // Normalize empty TOTP to null before saving.+                // Normalize empty TOTP to null before saving. The website field's+                // pending text is deliberately not committed here: it is added+                // only via the field's IME action or its trailing + icon.                 actions.updateDraft { it.copy(totpSecret = it.totpSecret?.ifBlank { null }) }                 if (d.id == 0L) {                     actions.saveDraft { newId -> onCreated(newId) }@@ -183,7 +182,8 @@ fun PasswordEditScreen(              Card(shape = RoundedCornerShape(10.dp), modifier = Modifier.fillMaxWidth()) {                 Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {-                    // Input for websites: pressing IME Done (Enter) adds to list+                    // Input for websites: the IME Send action or the trailing+                    // + icon adds the typed text to the list below.                     OutlinedTextField(                         value = websiteInput,                         onValueChange = { websiteInput = it },@@ -191,12 +191,20 @@ fun PasswordEditScreen(                         modifier = Modifier.fillMaxWidth(),                         keyboardOptions = KeyboardOptions(                             keyboardType = KeyboardType.Uri,-                            imeAction = ImeAction.Done,+                            imeAction = ImeAction.Send,                         ),-                        keyboardActions = KeyboardActions(onDone = {+                        keyboardActions = KeyboardActions(onSend = {                             addWebsiteFromInput()                             focusManager.clearFocus()-                        })+                        }),+                        trailingIcon = {+                            IconButton(+                                onClick = { addWebsiteFromInput() },+                                enabled = websiteInput.isNotBlank(),+                            ) {+                                IconAdd()+                            }+                        }                     )                      // websites preview as chips with remove X
passwords/src/test/java/com/vayunmathur/passwords/domain/WebsiteInputTest.kt
diff --git a/passwords/src/test/java/com/vayunmathur/passwords/domain/WebsiteInputTest.kt b/passwords/src/test/java/com/vayunmathur/passwords/domain/WebsiteInputTest.ktindex 2efe606d48..8c79c52953 100644--- a/passwords/src/test/java/com/vayunmathur/passwords/domain/WebsiteInputTest.kt+++ b/passwords/src/test/java/com/vayunmathur/passwords/domain/WebsiteInputTest.kt@@ -8,10 +8,11 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue  /**- * The pending-website merge is the hand-off that used to lose websites: the edit- * form keeps the field's text outside the draft until it is committed, so Save- * must merge it (scheme-less and full URLs alike) and the merged value must then- * round-trip through the Room converter and the KDBX field map.+ * The pending-website merge is the hand-off behind the edit form's explicit add+ * actions: the form keeps the field's text outside the draft until the IME Send+ * action or the trailing + icon commits it (scheme-less and full URLs alike),+ * and the merged value must then round-trip through the Room converter and the+ * KDBX field map.  */ class WebsiteInputTest { 
passwords/src/test/java/com/vayunmathur/passwords/ui/ComposeInteractionsExtraTest.kt
diff --git a/passwords/src/test/java/com/vayunmathur/passwords/ui/ComposeInteractionsExtraTest.kt b/passwords/src/test/java/com/vayunmathur/passwords/ui/ComposeInteractionsExtraTest.ktindex e5ef3979c9..9deece0265 100644--- a/passwords/src/test/java/com/vayunmathur/passwords/ui/ComposeInteractionsExtraTest.kt+++ b/passwords/src/test/java/com/vayunmathur/passwords/ui/ComposeInteractionsExtraTest.kt@@ -242,7 +242,7 @@ class ComposeInteractionsExtraTest {         assertTrue("note=work account" in copied, "got $copied")     } -    // ---- PasswordEditScreen: add website through the IME Done action ----+    // ---- PasswordEditScreen: add website through the IME Send action ----      @Test fun editScreenAddWebsiteViaImeDone() {         var draft = Password(id = 0, name = "New", username = "u", password = "p")
passwords/src/test/java/com/vayunmathur/passwords/ui/PasswordScreensComposeTest.kt
diff --git a/passwords/src/test/java/com/vayunmathur/passwords/ui/PasswordScreensComposeTest.kt b/passwords/src/test/java/com/vayunmathur/passwords/ui/PasswordScreensComposeTest.ktindex e91110eb03..d0daef61b7 100644--- a/passwords/src/test/java/com/vayunmathur/passwords/ui/PasswordScreensComposeTest.kt+++ b/passwords/src/test/java/com/vayunmathur/passwords/ui/PasswordScreensComposeTest.kt@@ -8,8 +8,11 @@ import androidx.compose.ui.test.hasScrollAction import androidx.compose.ui.test.hasText import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTextReplacement+import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick+import androidx.compose.ui.semantics.SemanticsProperties+import androidx.compose.ui.text.input.ImeAction import com.vayunmathur.passwords.data.Passkey import com.vayunmathur.passwords.data.Password import com.vayunmathur.passwords.ui.dialogs.PasskeyLinkDialog@@ -154,10 +157,24 @@ class PasswordScreensComposeTest {         assertTrue(!saved)     } -    @Test fun editScreenSaveCommitsPendingWebsiteWithoutImeDone() {-        // Regression (#949): typing a website and tapping Save without pressing-        // IME Done used to drop the website silently, because only IME Done-        // committed the field's local text into the draft.+    @Test fun editScreenWebsiteFieldUsesSendImeAction() {+        rule.setContent {+            PasswordEditScreen(+                state = PasswordEditUiState(saved = sample, draft = sample),+                actions = PasswordsActions.Noop,+            )+        }+        val fields = rule.onAllNodes(hasSetTextAction())+        val websiteField = fields[fields.fetchSemanticsNodes().size - 1]+        assertEquals(+            ImeAction.Send,+            websiteField.fetchSemanticsNode().config[SemanticsProperties.ImeAction],+        )+    }++    @Test fun editScreenSaveDoesNotCommitPendingWebsite() {+        // Follow-up (#949): Save must not auto-add the website field's pending+        // text; only the IME action or the trailing + icon adds it.         var draft = Password(id = 5, name = "GitHub", username = "octocat")         var savedDraft: Password? = null         val actions = object : PasswordsActions {@@ -173,10 +190,10 @@ class PasswordScreensComposeTest {         val fields = rule.onAllNodes(hasSetTextAction())         fields[fields.fetchSemanticsNodes().size - 1].performTextReplacement("example.com")         rule.onNodeWithText("Save").performClick()-        assertEquals(listOf("example.com"), savedDraft?.websites)+        assertEquals(emptyList(), savedDraft?.websites)     } -    @Test fun editScreenSaveWithImplausibleWebsiteShowsErrorAndDoesNotSave() {+    @Test fun editScreenSaveWithImplausiblePendingWebsiteStillSaves() {         var draft = Password(id = 5, name = "GitHub", username = "octocat")         var saved = false         val actions = object : PasswordsActions {@@ -192,9 +209,42 @@ class PasswordScreensComposeTest {         val fields = rule.onAllNodes(hasSetTextAction())         fields[fields.fetchSemanticsNodes().size - 1].performTextReplacement("exa mple.com")         rule.onNodeWithText("Save").performClick()-        // The error renders at the top of the form, above the scrolled-to website field.+        assertTrue(saved)+        assertEquals(emptyList(), draft.websites)+    }++    @Test fun editScreenTrailingAddIconAddsPendingWebsite() {+        var draft = Password(id = 5, name = "GitHub", username = "octocat")+        val actions = object : PasswordsActions {+            override fun updateDraft(transform: (Password) -> Password) { draft = transform(draft) }+        }+        rule.setContent {+            PasswordEditScreen(+                state = PasswordEditUiState(saved = draft, draft = draft),+                actions = actions,+            )+        }+        val fields = rule.onAllNodes(hasSetTextAction())+        fields[fields.fetchSemanticsNodes().size - 1].performTextReplacement("example.com")+        rule.onNodeWithContentDescription("Add").performClick()+        assertEquals(listOf("example.com"), draft.websites)+    }++    @Test fun editScreenTrailingAddWithImplausibleWebsiteShowsError() {+        var draft = Password(id = 5, name = "GitHub", username = "octocat")+        val actions = object : PasswordsActions {+            override fun updateDraft(transform: (Password) -> Password) { draft = transform(draft) }+        }+        rule.setContent {+            PasswordEditScreen(+                state = PasswordEditUiState(saved = draft, draft = draft),+                actions = actions,+            )+        }+        val fields = rule.onAllNodes(hasSetTextAction())+        fields[fields.fetchSemanticsNodes().size - 1].performTextReplacement("exa mple.com")+        rule.onNodeWithContentDescription("Add").performClick()         rule.onNodeWithText("Enter a website without spaces, e.g. example.com").assertExists()-        assertTrue(!saved)         assertEquals(emptyList(), draft.websites)     }