diff --git a/documentation/contacts.md b/documentation/contacts.md index 69559665..fba26ed9 100644 --- a/documentation/contacts.md +++ b/documentation/contacts.md @@ -40,7 +40,7 @@ Pull-to-refresh re-fetches the full contact list from the device. Telemetry loca A toolbar at the top provides: -**Search**: Matches contact name (case-insensitive) or public key hex prefix. Debounced at 300ms. +**Search**: Matches contact name (case-insensitive) or public key hex prefix. Names that start with the query are listed before other name matches, then key-prefix matches. Within each group the selected sort still applies. Debounced at 300ms. **Sort options**: - Latest Messages (by most recent message) diff --git a/documentation/design.md b/documentation/design.md index 423b53aa..dee9c2ce 100644 --- a/documentation/design.md +++ b/documentation/design.md @@ -154,7 +154,7 @@ What the code does: | Container | Call | Used for | Examples | |---|---|---|---| | Bottom sheet | `showMeshSheet` + `BottomSheetHeader` (28 calls in 17 files) | Choosing from a list, an item's actions, quick tools tied to the current screen | Language picker, notification mode, add contact/channel options, emoji and GIF pickers, node info, share contact, image actions | -| Draggable sheet | `showModalBottomSheet` + `DraggableScrollableSheet` | Tall, scrollable panels that need a drag size | `ContactRoutingSheet` (`routing_sheet.dart`), path editor, image send preview | +| Draggable sheet | `showModalBottomSheet` + `DraggableScrollableSheet` | Tall, scrollable panels that need a drag size | `ContactRoutingSheet` (`routing_sheet.dart`), image send preview | | Dialog | `showDialog` + `AlertDialog` (72 calls in 35 files) | Confirming an action, a short input (one to three fields), a short message | Disconnect (`showDisconnectDialog`), clear (`showConfirmClearDialog`), unsaved changes, edit node name, rename point | | Page | `Navigator.push(MaterialPageRoute(...))` | Anything with sections, many fields, its own save, or that the user stays in | App Settings, Repeater Settings, Themes, Theme editor, Message filter, Region management | @@ -165,6 +165,8 @@ Rules for new UI: 3. **Forms with sections, live remote values, or anything that needs Save/Discard → page.** Guard unsaved changes with `PopScope` and a discard dialog, as `repeater_settings_screen.dart` does. 4. Never stack a dialog on a sheet on a dialog. Close the sheet first, or move the flow to a page. +The manual path editor (`path_editor_sheet.dart`) is a fixed-height sheet, not a draggable one. The hop list and the hex path field stay pinned above a scrolling repeater list, including while the keyboard is open. The sheet uses the full height above the keyboard so a newly added hop is not scrolled under the title. + ## 7. App bars - Title: a plain localized string, ellipsized on one line. Use `AppBarTitle` on top-level and settings screens; it adds the connected node name as a subtitle and battery/SNR indicators when there is room, dropping them in that order on narrow widths. Use `AdaptiveAppBarTitle` for a plain one-line title. @@ -244,7 +246,7 @@ The current code does not yet follow this page everywhere: - **Large forms in dialogs.** `RadioSettingsDialog` (`widgets/radio_settings_dialog.dart`, nine inputs) and the contact settings dialog in `chat_screen.dart` are dialogs although they behave like forms. - **Dialog buttons.** `showDisconnectDialog` (`utils/dialog_utils.dart`) uses two `TextButton`s with no emphasis; `showConfirmClearDialog` uses a red `FilledButton`. - **Snackbars.** A few places still call `ScaffoldMessenger.showSnackBar` directly (`discovery_screen.dart`, `app_settings_screen.dart`, `message_filter_settings_screen.dart`, `region_management_screen.dart`, `helpers/image_send_flow.dart`) and so miss tap-to-dismiss and replace-instead-of-queue. -- **Small tap targets.** `FeatureToggleRow` refresh (32px) and 40px buttons in `chat_screen.dart`, `channel_chat_screen.dart`, `reaction_chips.dart`, `snr_indicator.dart`, `path_map_ui.dart`; 44px in `routing_sheet.dart`, `path_editor_sheet.dart`. +- **Small tap targets.** `FeatureToggleRow` refresh (32px) and 40px buttons in `chat_screen.dart`, `channel_chat_screen.dart`, `reaction_chips.dart`, `snr_indicator.dart`, `path_map_ui.dart`; 44px in `routing_sheet.dart`. - **Unknown placeholders.** Repeater and companion stats screens use `—`; `line_of_sight_map_screen.dart` uses `--`. - **Missing tooltip.** The Contacts FAB (`contacts_screen.dart`) has no tooltip; about 18 of 111 `IconButton`s have no tooltip nearby. - **Stale doc comments.** `SectionHeader` is described as "mono" but uses the sans `accentLabel`; the `StatusChip` comment sits above `meshContrastRatio`. diff --git a/documentation/routing-paths.md b/documentation/routing-paths.md index 74548258..90202fc4 100644 --- a/documentation/routing-paths.md +++ b/documentation/routing-paths.md @@ -62,4 +62,8 @@ Contacts/messages persist hop count, path bytes, and width. Legacy contact recor `resolvePathSelection` uses a route picked from history even when the radio itself holds no path for the contact, so repeater logins and commands use proven routes instead of flooding. +## Building a path by hand + +Chat → Routing → Manual opens the Build Path sheet. The hops you have added stay pinned at the top, including while the keyboard is open, and the one just added is highlighted. Under that list is the hex field, so a path can be typed without scrolling past every repeater. Search matches repeater and room names and hop hashes (the public-key prefix). Names that start with the query are listed before other substring matches, then hash-only matches. + For message-path actions, trace maps, and retry behavior, see [chat](chat-and-messaging.md), [channels](channels.md), and [map](map-and-location.md). diff --git a/lib/l10n/app_bg.arb b/lib/l10n/app_bg.arb index 913a0815..5135e0e4 100644 --- a/lib/l10n/app_bg.arb +++ b/lib/l10n/app_bg.arb @@ -2625,7 +2625,7 @@ "pathEditor_searchRepeaters": "Търсене на повторители", "pathEditor_advancedHex": "Разширено: суров шестнадесетичен път", "pathEditor_hexLabel": "Шестнадесетични префикси", - "pathEditor_hexHelper": "Два шестнадесетични идентификатора на скок, разделени със запетаи", + "pathEditor_hexHelper": "{count} шестнадесетични идентификатора на скок, разделени със запетаи", "pathEditor_invalidTokens": "Невалидни: {tokens}", "routing_lastWorked": "последно работил {when}", "routing_deliveryCounts": "{successes} доставени, {failures} неуспешни", diff --git a/lib/l10n/app_cs.arb b/lib/l10n/app_cs.arb index f72e9821..2e05031a 100644 --- a/lib/l10n/app_cs.arb +++ b/lib/l10n/app_cs.arb @@ -1243,7 +1243,7 @@ "pathEditor_searchRepeaters": "Hledat opakovače", "pathEditor_advancedHex": "Pokročilé: surová hex cesta", "pathEditor_hexLabel": "Hex prefixy", - "pathEditor_hexHelper": "Dva hex znaky na skok, oddělené čárkami", + "pathEditor_hexHelper": "{count} hex znaky na skok, oddělené čárkami", "pathEditor_invalidTokens": "Neplatné: {tokens}", "@pathEditor_invalidTokens": { "placeholders": { diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 40d00f84..1b568750 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -2791,7 +2791,7 @@ "pathEditor_searchRepeaters": "Repeater suchen", "pathEditor_advancedHex": "Erweitert: roher Hex-Pfad", "pathEditor_hexLabel": "Hex-Präfixe", - "pathEditor_hexHelper": "Zwei Hex-Zeichen pro Sprung, durch Kommas getrennt", + "pathEditor_hexHelper": "{count} Hex-Zeichen pro Sprung, durch Kommas getrennt", "pathEditor_invalidTokens": "Ungültig: {tokens}", "pathEditor_tooManyHops": "Maximal 64 Sprünge", "pathEditor_usePath": "Diesen Pfad verwenden", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index e18f6ed9..c2ed54a6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1391,10 +1391,17 @@ }, "pathEditor_noHops": "No hops yet. Tap repeaters below to add them in order, or save with no hops to send direct.", "pathEditor_addHops": "Add hops in order", - "pathEditor_searchRepeaters": "Search repeaters", + "pathEditor_searchRepeaters": "Search name or hash", "pathEditor_advancedHex": "Advanced: raw hex path", "pathEditor_hexLabel": "Hex prefixes", - "pathEditor_hexHelper": "Two hex characters per hop, separated by commas", + "pathEditor_hexHelper": "{count} hex characters per hop, separated by commas", + "@pathEditor_hexHelper": { + "placeholders": { + "count": { + "type": "int" + } + } + }, "pathEditor_invalidTokens": "Invalid: {tokens}", "@pathEditor_invalidTokens": { "placeholders": { diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 1b0ddb11..a7c49503 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -2675,7 +2675,7 @@ "pathEditor_searchRepeaters": "Buscar repetidores", "pathEditor_advancedHex": "Avanzado: ruta hexadecimal sin procesar", "pathEditor_hexLabel": "Prefijos hexadecimales", - "pathEditor_hexHelper": "Dos caracteres hexadecimales por salto, separados por comas.", + "pathEditor_hexHelper": "{count} caracteres hexadecimales por salto, separados por comas.", "pathEditor_invalidTokens": "Inválido: {tokens}", "pathEditor_tooManyHops": "Máximo 64 saltos", "pathEditor_usePath": "Usar esta ruta", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index de3c1be3..9aa4daa1 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -2675,7 +2675,7 @@ "pathEditor_searchRepeaters": "Rechercher des répétiteurs", "pathEditor_advancedHex": "Avancé : chemin hexadécimal brut", "pathEditor_hexLabel": "Préfixes hexadécimaux", - "pathEditor_hexHelper": "Deux caractères hexadécimaux par saut, séparés par des virgules.", + "pathEditor_hexHelper": "{count} caractères hexadécimaux par saut, séparés par des virgules.", "pathEditor_invalidTokens": "Invalide : {tokens}", "pathEditor_tooManyHops": "Maximum 64 sauts", "pathEditor_usePath": "Utiliser ce chemin", diff --git a/lib/l10n/app_hu.arb b/lib/l10n/app_hu.arb index ba73a0d6..f079dce3 100644 --- a/lib/l10n/app_hu.arb +++ b/lib/l10n/app_hu.arb @@ -2663,7 +2663,7 @@ "pathEditor_searchRepeaters": "Ismétlő keresése", "pathEditor_advancedHex": "Haladó: nyers hexadecimális útvonal", "pathEditor_hexLabel": "Hexadecimális előtagok", - "pathEditor_hexHelper": "Két hexadecimális karakter ugrásonként, vesszővel elválasztva", + "pathEditor_hexHelper": "{count} hexadecimális karakter ugrásonként, vesszővel elválasztva", "pathEditor_invalidTokens": "Érvénytelen: {tokens}", "routing_lastWorked": "dolgozott {when}", "routing_deliveryCounts": "{successes} kézbesítve, {failures} sikertelen", diff --git a/lib/l10n/app_it.arb b/lib/l10n/app_it.arb index 8d6bd2ec..9e0393bf 100644 --- a/lib/l10n/app_it.arb +++ b/lib/l10n/app_it.arb @@ -2680,7 +2680,7 @@ "pathEditor_searchRepeaters": "Cerca ripetitori", "pathEditor_advancedHex": "Avanzato: percorso esadecimale grezzo", "pathEditor_hexLabel": "Prefissi esadecimali", - "pathEditor_hexHelper": "Due caratteri esadecimali per ogni salto, separati da virgole.", + "pathEditor_hexHelper": "{count} caratteri esadecimali per ogni salto, separati da virgole.", "pathEditor_invalidTokens": "Non valido: {tokens}", "routing_lastWorked": "ha funzionato {when}", "pathEditor_tooManyHops": "Massimo 64 salti", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 0a3b8931..a7682fd6 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -2675,7 +2675,7 @@ "pathEditor_searchRepeaters": "リピータを検索", "pathEditor_advancedHex": "詳細: 生の 16 進経路", "pathEditor_hexLabel": "16 進接頭辞", - "pathEditor_hexHelper": "ホップごとに 16 進数 2 文字をカンマ区切りで入力します", + "pathEditor_hexHelper": "ホップごとに 16 進数 {count} 文字をカンマ区切りで入力します", "pathEditor_invalidTokens": "無効: {tokens}", "pathEditor_tooManyHops": "最大 64 ホップ", "pathEditor_usePath": "この経路を使用", diff --git a/lib/l10n/app_ko.arb b/lib/l10n/app_ko.arb index dcaf27a3..1fcb9980 100644 --- a/lib/l10n/app_ko.arb +++ b/lib/l10n/app_ko.arb @@ -2579,7 +2579,7 @@ "pathEditor_searchRepeaters": "리피터 검색", "pathEditor_advancedHex": "고급: 원시 HEX 경로", "pathEditor_hexLabel": "HEX 접두사", - "pathEditor_hexHelper": "각 홉마다 2개의 16진수 바이트, 쉼표로 구분", + "pathEditor_hexHelper": "각 홉마다 {count}개의 16진수 문자, 쉼표로 구분", "pathEditor_invalidTokens": "유효하지 않음: {tokens}", "pathEditor_tooManyHops": "최대 64개의 홉", "pathEditor_usePath": "이 경로 사용", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 53e641fa..800269da 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -4720,7 +4720,7 @@ abstract class AppLocalizations { /// No description provided for @pathEditor_searchRepeaters. /// /// In en, this message translates to: - /// **'Search repeaters'** + /// **'Search name or hash'** String get pathEditor_searchRepeaters; /// No description provided for @pathEditor_advancedHex. @@ -4738,8 +4738,8 @@ abstract class AppLocalizations { /// No description provided for @pathEditor_hexHelper. /// /// In en, this message translates to: - /// **'Two hex characters per hop, separated by commas'** - String get pathEditor_hexHelper; + /// **'{count} hex characters per hop, separated by commas'** + String pathEditor_hexHelper(int count); /// No description provided for @pathEditor_invalidTokens. /// diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index cc0a9670..b89785cf 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -2714,8 +2714,9 @@ class AppLocalizationsBg extends AppLocalizations { String get pathEditor_hexLabel => 'Шестнадесетични префикси'; @override - String get pathEditor_hexHelper => - 'Два шестнадесетични идентификатора на скок, разделени със запетаи'; + String pathEditor_hexHelper(int count) { + return '$count шестнадесетични идентификатора на скок, разделени със запетаи'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_cs.dart b/lib/l10n/app_localizations_cs.dart index 60ad5ee3..112ad4fd 100644 --- a/lib/l10n/app_localizations_cs.dart +++ b/lib/l10n/app_localizations_cs.dart @@ -2706,7 +2706,9 @@ class AppLocalizationsCs extends AppLocalizations { String get pathEditor_hexLabel => 'Hex prefixy'; @override - String get pathEditor_hexHelper => 'Dva hex znaky na skok, oddělené čárkami'; + String pathEditor_hexHelper(int count) { + return '$count hex znaky na skok, oddělené čárkami'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 587287f7..f9b79f7c 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -2717,8 +2717,9 @@ class AppLocalizationsDe extends AppLocalizations { String get pathEditor_hexLabel => 'Hex-Präfixe'; @override - String get pathEditor_hexHelper => - 'Zwei Hex-Zeichen pro Sprung, durch Kommas getrennt'; + String pathEditor_hexHelper(int count) { + return '$count Hex-Zeichen pro Sprung, durch Kommas getrennt'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index f73db6d1..bba7e7e8 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -2661,7 +2661,7 @@ class AppLocalizationsEn extends AppLocalizations { String get pathEditor_addHops => 'Add hops in order'; @override - String get pathEditor_searchRepeaters => 'Search repeaters'; + String get pathEditor_searchRepeaters => 'Search name or hash'; @override String get pathEditor_advancedHex => 'Advanced: raw hex path'; @@ -2670,8 +2670,9 @@ class AppLocalizationsEn extends AppLocalizations { String get pathEditor_hexLabel => 'Hex prefixes'; @override - String get pathEditor_hexHelper => - 'Two hex characters per hop, separated by commas'; + String pathEditor_hexHelper(int count) { + return '$count hex characters per hop, separated by commas'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 8dd0aa61..37cf28c6 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -2707,8 +2707,9 @@ class AppLocalizationsEs extends AppLocalizations { String get pathEditor_hexLabel => 'Prefijos hexadecimales'; @override - String get pathEditor_hexHelper => - 'Dos caracteres hexadecimales por salto, separados por comas.'; + String pathEditor_hexHelper(int count) { + return '$count caracteres hexadecimales por salto, separados por comas.'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 9e1cde19..2ef6d2fc 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -2711,8 +2711,9 @@ class AppLocalizationsFr extends AppLocalizations { String get pathEditor_hexLabel => 'Préfixes hexadécimaux'; @override - String get pathEditor_hexHelper => - 'Deux caractères hexadécimaux par saut, séparés par des virgules.'; + String pathEditor_hexHelper(int count) { + return '$count caractères hexadécimaux par saut, séparés par des virgules.'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index fae906b6..0cafc066 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -2704,8 +2704,9 @@ class AppLocalizationsHu extends AppLocalizations { String get pathEditor_hexLabel => 'Hexadecimális előtagok'; @override - String get pathEditor_hexHelper => - 'Két hexadecimális karakter ugrásonként, vesszővel elválasztva'; + String pathEditor_hexHelper(int count) { + return '$count hexadecimális karakter ugrásonként, vesszővel elválasztva'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 9d96718d..f0352798 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -2711,8 +2711,9 @@ class AppLocalizationsIt extends AppLocalizations { String get pathEditor_hexLabel => 'Prefissi esadecimali'; @override - String get pathEditor_hexHelper => - 'Due caratteri esadecimali per ogni salto, separati da virgole.'; + String pathEditor_hexHelper(int count) { + return '$count caratteri esadecimali per ogni salto, separati da virgole.'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 10908f1e..0aaef47b 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -2587,7 +2587,9 @@ class AppLocalizationsJa extends AppLocalizations { String get pathEditor_hexLabel => '16 進接頭辞'; @override - String get pathEditor_hexHelper => 'ホップごとに 16 進数 2 文字をカンマ区切りで入力します'; + String pathEditor_hexHelper(int count) { + return 'ホップごとに 16 進数 $count 文字をカンマ区切りで入力します'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 2ed52089..5b99499f 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -2590,7 +2590,9 @@ class AppLocalizationsKo extends AppLocalizations { String get pathEditor_hexLabel => 'HEX 접두사'; @override - String get pathEditor_hexHelper => '각 홉마다 2개의 16진수 바이트, 쉼표로 구분'; + String pathEditor_hexHelper(int count) { + return '각 홉마다 $count개의 16진수 문자, 쉼표로 구분'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index cc092841..6d854004 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -2696,8 +2696,9 @@ class AppLocalizationsNl extends AppLocalizations { String get pathEditor_hexLabel => 'Hex-prefixen'; @override - String get pathEditor_hexHelper => - 'Twee hex-tekens per hop, gescheiden door komma\'s'; + String pathEditor_hexHelper(int count) { + return '$count hex-tekens per hop, gescheiden door komma\'s'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 62a18751..04bf7d6c 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -2738,8 +2738,9 @@ class AppLocalizationsPl extends AppLocalizations { String get pathEditor_hexLabel => 'Prefiksy heksadecymalne'; @override - String get pathEditor_hexHelper => - 'Dwa znaki szesnastkowe na każdym kroku, oddzielone przecinkami'; + String pathEditor_hexHelper(int count) { + return '$count znaki szesnastkowe na każdym kroku, oddzielone przecinkami'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 48a93255..feb15cdc 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -2706,8 +2706,9 @@ class AppLocalizationsPt extends AppLocalizations { String get pathEditor_hexLabel => 'Prefixos hexadecimais'; @override - String get pathEditor_hexHelper => - 'Dois caracteres hexadecimais por salto, separados por vírgulas.'; + String pathEditor_hexHelper(int count) { + return '$count caracteres hexadecimais por salto, separados por vírgulas.'; + } @override String pathEditor_invalidTokens(String tokens) { @@ -10231,8 +10232,9 @@ class AppLocalizationsPtPt extends AppLocalizationsPt { String get pathEditor_hexLabel => 'Prefixos hex'; @override - String get pathEditor_hexHelper => - 'Dois caracteres hex por hop, separados por vírgulas'; + String pathEditor_hexHelper(int count) { + return '$count caracteres hex por hop, separados por vírgulas'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index b2d7a486..d0d031c4 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -2717,8 +2717,9 @@ class AppLocalizationsRu extends AppLocalizations { String get pathEditor_hexLabel => 'Префиксы шестнадцатеричной системы'; @override - String get pathEditor_hexHelper => - 'Два шестнадцатеричных символа на каждом шаге, разделенные запятыми.'; + String pathEditor_hexHelper(int count) { + return '$count шестнадцатеричных символа на каждом шаге, разделенные запятыми.'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 0c1327b4..deec1017 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -2708,8 +2708,9 @@ class AppLocalizationsSk extends AppLocalizations { String get pathEditor_hexLabel => 'Prefiksy pre hexadecimálne čísla'; @override - String get pathEditor_hexHelper => - 'Dve hexové čísla na každý krok, oddelené čiarkami'; + String pathEditor_hexHelper(int count) { + return '$count hexové čísla na každý krok, oddelené čiarkami'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 3701f9e0..573c0cd4 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -2705,8 +2705,9 @@ class AppLocalizationsSl extends AppLocalizations { String get pathEditor_hexLabel => 'Predfiks za heksadecimalno šifro'; @override - String get pathEditor_hexHelper => - 'Dva šestbitna znaka na vsak skok, ločena z vejico'; + String pathEditor_hexHelper(int count) { + return '$count šestnajstiških znakov na vsak skok, ločenih z vejico'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 9aa969ce..fc3c7539 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -2684,8 +2684,9 @@ class AppLocalizationsSv extends AppLocalizations { String get pathEditor_hexLabel => 'Hex-prefikser'; @override - String get pathEditor_hexHelper => - 'Två hextecken per hopp, separerade med kommatecken'; + String pathEditor_hexHelper(int count) { + return '$count hextecken per hopp, separerade med kommatecken'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index de2125bc..c0b66621 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -2715,8 +2715,9 @@ class AppLocalizationsUk extends AppLocalizations { 'Префікси для шестнадцяткової системи числення'; @override - String get pathEditor_hexHelper => - 'Два шестизначні символи на кожний крок, розділені комами'; + String pathEditor_hexHelper(int count) { + return '$count шістнадцяткові символи на кожний крок, розділені комами'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 241d78de..d1e28290 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -2546,7 +2546,9 @@ class AppLocalizationsZh extends AppLocalizations { String get pathEditor_hexLabel => '十六进制前缀'; @override - String get pathEditor_hexHelper => '每跳使用两个十六进制字符,用逗号分隔。'; + String pathEditor_hexHelper(int count) { + return '每跳使用$count个十六进制字符,用逗号分隔。'; + } @override String pathEditor_invalidTokens(String tokens) { diff --git a/lib/l10n/app_nl.arb b/lib/l10n/app_nl.arb index 2f192869..93f61445 100644 --- a/lib/l10n/app_nl.arb +++ b/lib/l10n/app_nl.arb @@ -2682,7 +2682,7 @@ "pathEditor_searchRepeaters": "Repeaters zoeken", "pathEditor_advancedHex": "Geavanceerd: ruwe hex-pad", "pathEditor_hexLabel": "Hex-prefixen", - "pathEditor_hexHelper": "Twee hex-tekens per hop, gescheiden door komma's", + "pathEditor_hexHelper": "{count} hex-tekens per hop, gescheiden door komma's", "pathEditor_invalidTokens": "Ongeldig: {tokens}", "pathEditor_tooManyHops": "Maximaal 64 hops", "pathEditor_usePath": "Dit pad gebruiken", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index af3783a1..e4850bd4 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -2658,7 +2658,7 @@ "pathEditor_searchRepeaters": "Funkcje powtarzania", "pathEditor_advancedHex": "Zaawansowane: ścieżka w formacie szesnastkowym", "pathEditor_hexLabel": "Prefiksy heksadecymalne", - "pathEditor_hexHelper": "Dwa znaki szesnastkowe na każdym kroku, oddzielone przecinkami", + "pathEditor_hexHelper": "{count} znaki szesnastkowe na każdym kroku, oddzielone przecinkami", "pathEditor_invalidTokens": "Nieprawidłowe: {tokens}", "pathEditor_tooManyHops": "Maksymalnie 64 hopów", "pathEditor_usePath": "Użyj tej ścieżki.", diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index ad24e07a..51dbc222 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -2540,7 +2540,7 @@ "pathEditor_searchRepeaters": "Encontrar repetidores", "pathEditor_advancedHex": "Avançado: caminho hexadecimal bruto", "pathEditor_hexLabel": "Prefixos hexadecimais", - "pathEditor_hexHelper": "Dois caracteres hexadecimais por salto, separados por vírgulas.", + "pathEditor_hexHelper": "{count} caracteres hexadecimais por salto, separados por vírgulas.", "pathEditor_invalidTokens": "Inválido: {tokens}", "routing_lastWorked": "funcionou {when}", "pathEditor_tooManyHops": "Máximo de 64 saltos", diff --git a/lib/l10n/app_pt_PT.arb b/lib/l10n/app_pt_PT.arb index 80218599..7f093675 100644 --- a/lib/l10n/app_pt_PT.arb +++ b/lib/l10n/app_pt_PT.arb @@ -758,7 +758,7 @@ "pathEditor_searchRepeaters": "Pesquisar repetidores", "pathEditor_advancedHex": "Avançado: caminho hex em bruto", "pathEditor_hexLabel": "Prefixos hex", - "pathEditor_hexHelper": "Dois caracteres hex por hop, separados por vírgulas", + "pathEditor_hexHelper": "{count} caracteres hex por hop, separados por vírgulas", "pathEditor_invalidTokens": "Inválido: {tokens}", "pathEditor_tooManyHops": "Máximo de 64 hops", "pathEditor_usePath": "Usar este caminho", diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index f5ff336c..c15c5e40 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -1922,7 +1922,7 @@ "pathEditor_searchRepeaters": "Поиск повторителей", "pathEditor_advancedHex": "Продвинутый уровень: прямой путь в шестнадцатеричном формате", "pathEditor_hexLabel": "Префиксы шестнадцатеричной системы", - "pathEditor_hexHelper": "Два шестнадцатеричных символа на каждом шаге, разделенные запятыми.", + "pathEditor_hexHelper": "{count} шестнадцатеричных символа на каждом шаге, разделенные запятыми.", "pathEditor_invalidTokens": "Неверно: {tokens}", "routing_lastWorked": "работал {when}", "routing_deliveryCounts": "{successes} доставлено, {failures} не доставлено", diff --git a/lib/l10n/app_sk.arb b/lib/l10n/app_sk.arb index c582c8f4..ea09a446 100644 --- a/lib/l10n/app_sk.arb +++ b/lib/l10n/app_sk.arb @@ -2625,7 +2625,7 @@ "pathEditor_searchRepeaters": "Hľadať opakované", "pathEditor_advancedHex": "Pokročilé: pôvodná hexová cesta", "pathEditor_hexLabel": "Prefiksy pre hexadecimálne čísla", - "pathEditor_hexHelper": "Dve hexové čísla na každý krok, oddelené čiarkami", + "pathEditor_hexHelper": "{count} hexové čísla na každý krok, oddelené čiarkami", "routing_lastWorked": "fungovala {when}", "pathEditor_invalidTokens": "Neplatné: {tokens}", "routing_deliveryCounts": "{successes} doručených, {failures} neúspešných", diff --git a/lib/l10n/app_sl.arb b/lib/l10n/app_sl.arb index 3dcbeb94..40fb0b5b 100644 --- a/lib/l10n/app_sl.arb +++ b/lib/l10n/app_sl.arb @@ -2534,7 +2534,7 @@ "pathEditor_searchRepeaters": "Iskanje ponovitev", "pathEditor_advancedHex": "Napredno: surovi šestnajstni pot", "pathEditor_hexLabel": "Predfiks za heksadecimalno šifro", - "pathEditor_hexHelper": "Dva šestbitna znaka na vsak skok, ločena z vejico", + "pathEditor_hexHelper": "{count} šestnajstiških znakov na vsak skok, ločenih z vejico", "pathEditor_invalidTokens": "Neveljaven: {tokens}", "pathEditor_tooManyHops": "Največ 64 hopov", "pathEditor_usePath": "Uporabite to poto", diff --git a/lib/l10n/app_sv.arb b/lib/l10n/app_sv.arb index 7ec4e120..7fc55b2e 100644 --- a/lib/l10n/app_sv.arb +++ b/lib/l10n/app_sv.arb @@ -2529,7 +2529,7 @@ "pathEditor_searchRepeaters": "Sök repeaters", "pathEditor_advancedHex": "Avancerat: rå rutt i hexformat", "pathEditor_hexLabel": "Hex-prefikser", - "pathEditor_hexHelper": "Två hextecken per hopp, separerade med kommatecken", + "pathEditor_hexHelper": "{count} hextecken per hopp, separerade med kommatecken", "pathEditor_invalidTokens": "Ogiltigt: {tokens}", "pathEditor_tooManyHops": "Maximalt 64 hopp", "pathEditor_usePath": "Använd den här rutten", diff --git a/lib/l10n/app_uk.arb b/lib/l10n/app_uk.arb index 16d0ca20..e1d60645 100644 --- a/lib/l10n/app_uk.arb +++ b/lib/l10n/app_uk.arb @@ -2598,7 +2598,7 @@ "pathEditor_searchRepeaters": "Пошук повторювачів", "pathEditor_advancedHex": "Просунутий рівень: пряма шлях у форматі шестнадцяткової системи.", "pathEditor_hexLabel": "Префікси для шестнадцяткової системи числення", - "pathEditor_hexHelper": "Два шестизначні символи на кожний крок, розділені комами", + "pathEditor_hexHelper": "{count} шістнадцяткові символи на кожний крок, розділені комами", "pathEditor_invalidTokens": "Неправильно: {tokens}", "routing_lastWorked": "працював {when}", "routing_deliveryCounts": "{successes} доставлено, {failures} не доставлено", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 6b70ddb0..ce2a3aa8 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -2538,7 +2538,7 @@ "pathEditor_searchRepeaters": "重复搜索", "pathEditor_advancedHex": "高级:原始十六进制路径", "pathEditor_hexLabel": "十六进制前缀", - "pathEditor_hexHelper": "每跳使用两个十六进制字符,用逗号分隔。", + "pathEditor_hexHelper": "每跳使用{count}个十六进制字符,用逗号分隔。", "pathEditor_invalidTokens": "无效:{tokens}", "pathEditor_tooManyHops": "最多 64 跳", "pathEditor_usePath": "请使用此路径", diff --git a/lib/screens/contacts_screen.dart b/lib/screens/contacts_screen.dart index 2d60dd3a..97c439a9 100644 --- a/lib/screens/contacts_screen.dart +++ b/lib/screens/contacts_screen.dart @@ -1201,26 +1201,26 @@ class _ContactsScreenState extends State { }).toList(); } - switch (viewState.contactsSortOption) { - case ContactSortOption.lastSeen: - filtered.sort( - (a, b) => - resolveContactLastSeen(b).compareTo(resolveContactLastSeen(a)), - ); - break; - case ContactSortOption.recentMessages: - final lastMessageAt = { - for (final c in filtered) c: _lastMessageTime(connector, c), - }; - filtered.sort((a, b) => lastMessageAt[b]!.compareTo(lastMessageAt[a]!)); - break; - case ContactSortOption.name: - filtered.sort( - (a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()), - ); - break; + final lastMessageAt = + viewState.contactsSortOption == ContactSortOption.recentMessages + ? {for (final c in filtered) c: _lastMessageTime(connector, c)} + : null; + int tieBreak(Contact a, Contact b) { + switch (viewState.contactsSortOption) { + case ContactSortOption.lastSeen: + return resolveContactLastSeen(b).compareTo(resolveContactLastSeen(a)); + case ContactSortOption.recentMessages: + return lastMessageAt![b]!.compareTo(lastMessageAt[a]!); + case ContactSortOption.name: + return a.name.toLowerCase().compareTo(b.name.toLowerCase()); + } } + filtered.sort( + (a, b) => + compareContactQueryRank(a, b, viewState.contactsSearchText, tieBreak), + ); + return filtered; } @@ -1409,11 +1409,14 @@ class _ContactsScreenState extends State { builder: (builderContext, setDialogState) { final filteredContacts = filterQuery.isEmpty ? sortedContacts - : sortedContacts + : (sortedContacts .where( (contact) => matchesContactQuery(contact, filterQuery), ) - .toList(); + .toList() + ..sort( + (a, b) => compareContactQueryRank(a, b, filterQuery), + )); return AlertDialog( title: Text( isEditing diff --git a/lib/screens/discovery_screen.dart b/lib/screens/discovery_screen.dart index 24506563..5c5ad42a 100644 --- a/lib/screens/discovery_screen.dart +++ b/lib/screens/discovery_screen.dart @@ -662,17 +662,32 @@ class _DiscoveryScreenState extends State { return _matchesTypeFilter(contact); }).toList(); - switch (sortOption) { - case ContactSortOption.lastSeen: - filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen)); - break; - case ContactSortOption.name: - filtered.sort( - (a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()), - ); - break; - default: - break; + int tieBreak(Contact a, Contact b) { + switch (sortOption) { + case ContactSortOption.lastSeen: + return b.lastSeen.compareTo(a.lastSeen); + case ContactSortOption.name: + return a.name.toLowerCase().compareTo(b.name.toLowerCase()); + default: + return a.name.toLowerCase().compareTo(b.name.toLowerCase()); + } + } + + if (searchQuery.trim().isEmpty) { + switch (sortOption) { + case ContactSortOption.lastSeen: + filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen)); + case ContactSortOption.name: + filtered.sort( + (a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()), + ); + default: + break; + } + } else { + filtered.sort( + (a, b) => compareContactQueryRank(a, b, searchQuery, tieBreak), + ); } return filtered; diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart index 018b7ec8..5715fb16 100644 --- a/lib/screens/map_screen.dart +++ b/lib/screens/map_screen.dart @@ -2292,13 +2292,14 @@ class _MapScreenState extends State with WidgetsBindingObserver { ) { final query = _searchQuery.trim().toLowerCase(); final matches = - allContacts.where((c) => matchesContactQuery(c, query)).toList() - ..sort((a, b) { + allContacts.where((c) => matchesContactQuery(c, query)).toList()..sort( + (a, b) => compareContactQueryRank(a, b, query, (a, b) { if (a.hasLocation != b.hasLocation) { return a.hasLocation ? -1 : 1; } return b.lastHeard.compareTo(a.lastHeard); - }); + }), + ); final results = matches.take(8).toList(); return Container( margin: const EdgeInsets.only(top: 6), @@ -3464,6 +3465,15 @@ class _MapScreenState extends State with WidgetsBindingObserver { contact.type != advTypeRoom, ) .toList(); + final people = allContacts + .where( + (contact) => + query.isEmpty || matchesContactQuery(contact, query), + ) + .toList(); + if (query.isNotEmpty) { + people.sort((a, b) => compareContactQueryRank(a, b, query)); + } return SafeArea( child: SingleChildScrollView( child: Column( @@ -3499,29 +3509,23 @@ class _MapScreenState extends State with WidgetsBindingObserver { }, ), ), - ...allContacts - .where( - (contact) => - query.isEmpty || - matchesContactQuery(contact, query), - ) - .map((contact) { - return ListTile( - leading: const Icon(Icons.person), - title: Text(contact.name), - onTap: () { - Navigator.pop(sheetContext); - if (!_markerFits( - context, - markerText, - maxContactMessageBytes(), - )) { - return; - } - liveConnector.sendMessage(contact, markerText); - }, - ); - }), + ...people.map((contact) { + return ListTile( + leading: const Icon(Icons.person), + title: Text(contact.name), + onTap: () { + Navigator.pop(sheetContext); + if (!_markerFits( + context, + markerText, + maxContactMessageBytes(), + )) { + return; + } + liveConnector.sendMessage(contact, markerText); + }, + ); + }), Padding( padding: const EdgeInsets.fromLTRB(16, 12, 16, 4), child: Text( diff --git a/lib/utils/contact_search.dart b/lib/utils/contact_search.dart index 7a82c53a..eaad99c2 100644 --- a/lib/utils/contact_search.dart +++ b/lib/utils/contact_search.dart @@ -2,31 +2,55 @@ import '../models/contact.dart'; export 'contact_filter_types.dart'; -bool matchesContactQuery(Contact contact, String query) { - final normalizedQuery = query.trim().toLowerCase(); - if (normalizedQuery.isEmpty) return true; +/// How closely a contact matches a search query. Lower ranks sort first. +enum ContactQueryRank { namePrefix, nameContains, keyPrefix } - if (contact.name.toLowerCase().contains(normalizedQuery)) { - return true; +/// Rank for [query], or null when the contact does not match. +/// +/// Names that start with the query come before other substring matches. +/// A public-key / hop-hash prefix matches only when the name does not. +ContactQueryRank? rankContactQuery(Contact contact, String query) { + final normalized = query.trim().toLowerCase(); + if (normalized.isEmpty) return ContactQueryRank.namePrefix; + + final name = contact.name.toLowerCase(); + if (name.startsWith(normalized)) return ContactQueryRank.namePrefix; + if (name.contains(normalized)) return ContactQueryRank.nameContains; + if (_publicKeyPrefixMatches(contact, normalized)) { + return ContactQueryRank.keyPrefix; } + return null; +} - final hexPrefix = _extractHexPrefix(normalizedQuery); - if (hexPrefix == null) return false; - - return contact.publicKeyHex.toLowerCase().startsWith(hexPrefix); +bool matchesContactQuery(Contact contact, String query) { + return rankContactQuery(contact, query) != null; } bool matchesDiscoveryContactQuery(Contact contact, String query) { - final normalizedQuery = query.trim().toLowerCase(); - if (normalizedQuery.isEmpty) return true; + return matchesContactQuery(contact, query); +} - if (contact.name.toLowerCase().contains(normalizedQuery)) { - return true; - } +/// Sorts prefix matches ahead of other substring matches, then key matches. +/// +/// [tieBreak] orders contacts that share a rank. With an empty query every +/// contact shares the top rank, so [tieBreak] is the whole order. +int compareContactQueryRank( + Contact a, + Contact b, + String query, [ + int Function(Contact a, Contact b)? tieBreak, +]) { + final left = rankContactQuery(a, query); + final right = rankContactQuery(b, query); + final byRank = (left?.index ?? 3).compareTo(right?.index ?? 3); + if (byRank != 0) return byRank; + return tieBreak?.call(a, b) ?? + a.name.toLowerCase().compareTo(b.name.toLowerCase()); +} +bool _publicKeyPrefixMatches(Contact contact, String normalizedQuery) { final hexPrefix = _extractHexPrefix(normalizedQuery); - if (hexPrefix == null) return false; - + if (hexPrefix == null || contact.publicKey.isEmpty) return false; return contact.publicKeyHex.toLowerCase().startsWith(hexPrefix); } diff --git a/lib/widgets/path_editor_sheet.dart b/lib/widgets/path_editor_sheet.dart index f20aad1c..73a34b31 100644 --- a/lib/widgets/path_editor_sheet.dart +++ b/lib/widgets/path_editor_sheet.dart @@ -1,12 +1,16 @@ -import 'dart:typed_data'; +import 'dart:async'; +import 'dart:math' as math; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import '../connector/meshcore_protocol.dart'; import '../helpers/path_helper.dart'; import '../l10n/contact_localization.dart'; import '../l10n/l10n.dart'; import '../models/contact.dart'; +import '../theme/mesh_theme.dart'; +import '../utils/contact_search.dart'; class PathEditorSheet extends StatefulWidget { final List availableContacts; @@ -30,19 +34,25 @@ class PathEditorSheet extends StatefulWidget { context: context, isScrollControlled: true, useSafeArea: true, - builder: (context) => Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), - child: FractionallySizedBox( - heightFactor: 0.9, - child: PathEditorSheet( - availableContacts: availableContacts, - initialPath: initialPath, - pathHashByteWidth: pathHashByteWidth, + builder: (context) { + final keyboard = MediaQuery.viewInsetsOf(context).bottom; + return Padding( + padding: EdgeInsets.only(bottom: keyboard), + child: Align( + alignment: Alignment.bottomCenter, + child: FractionallySizedBox( + // The keyboard already shrinks the sheet. Use the full band + // above it so the hop list is not clipped under the title. + heightFactor: keyboard > 0 ? 1 : 0.92, + child: PathEditorSheet( + availableContacts: availableContacts, + initialPath: initialPath, + pathHashByteWidth: pathHashByteWidth, + ), + ), ), - ), - ), + ); + }, ); } @@ -62,10 +72,13 @@ class _PathEditorSheetState extends State { final List<_Hop> _hops = []; final _hexController = TextEditingController(); + final _hopScroll = ScrollController(); String? _hexError; bool _syncingHex = false; String _search = ''; int _nextHopId = 0; + int? _highlightedHopId; + Timer? _highlightTimer; @override void initState() { @@ -81,18 +94,25 @@ class _PathEditorSheetState extends State { @override void dispose() { + _highlightTimer?.cancel(); + _hopScroll.dispose(); _hexController.dispose(); super.dispose(); } + int get _hashChars { + final width = widget.pathHashByteWidth.clamp(1, pubKeySize).toInt(); + return width * 2; + } + List get _repeaters { - final query = _search.trim().toLowerCase(); + final query = _search.trim(); return widget.availableContacts .where((c) => c.type == advTypeRepeater || c.type == advTypeRoom) .where((c) => c.publicKey.isNotEmpty) - .where((c) => query.isEmpty || c.name.toLowerCase().contains(query)) + .where((c) => rankContactQuery(c, query) != null) .toList() - ..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase())); + ..sort((a, b) => compareContactQueryRank(a, b, query)); } void _syncHexFromHops() { @@ -129,6 +149,7 @@ class _PathEditorSheetState extends State { return; } _hexError = null; + final previous = _hops.length; _hops ..clear() ..addAll( @@ -140,6 +161,9 @@ class _PathEditorSheetState extends State { return _Hop(_nextHopId++, Uint8List.fromList(bytes)); }), ); + if (_hops.length > previous && _hops.isNotEmpty) { + _markHopAdded(_hops.last.id); + } }); } @@ -148,14 +172,38 @@ class _PathEditorSheetState extends State { final width = widget.pathHashByteWidth .clamp(1, contact.publicKey.length) .toInt(); + HapticFeedback.selectionClick(); setState(() { - _hops.add( - _Hop( - _nextHopId++, - Uint8List.fromList(contact.publicKey.sublist(0, width)), - ), + final hop = _Hop( + _nextHopId++, + Uint8List.fromList(contact.publicKey.sublist(0, width)), ); + _hops.add(hop); _syncHexFromHops(); + _markHopAdded(hop.id); + }); + } + + void _markHopAdded(int id) { + _highlightedHopId = id; + _highlightTimer?.cancel(); + _highlightTimer = Timer(const Duration(milliseconds: 1400), () { + if (!mounted) return; + setState(() { + if (_highlightedHopId == id) _highlightedHopId = null; + }); + }); + _revealLatestHop(); + } + + void _revealLatestHop() { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted || !_hopScroll.hasClients) return; + _hopScroll.animateTo( + _hopScroll.position.maxScrollExtent, + duration: const Duration(milliseconds: 180), + curve: Curves.easeOut, + ); }); } @@ -182,7 +230,14 @@ class _PathEditorSheetState extends State { Navigator.pop(context, Uint8List.fromList(bytes)); } - Widget _hopTile(BuildContext context, int index) { + String _contactHopHex(Contact contact) { + final width = widget.pathHashByteWidth + .clamp(1, contact.publicKey.length) + .toInt(); + return PathHelper.formatHopHex(contact.publicKey.sublist(0, width)); + } + + Widget _hopTile(BuildContext context, int index, {required bool singleLine}) { final l10n = context.l10n; final scheme = Theme.of(context).colorScheme; final hop = _hops[index]; @@ -200,41 +255,61 @@ class _PathEditorSheetState extends State { : matches.length == 1 ? matches.first.name : matches.map((c) => c.name).join(' | '); + final highlighted = hop.id == _highlightedHopId; - return ListTile( + final label = name ?? l10n.pathEditor_unknownHop; + final hash = Text(hex, style: MeshTheme.mono(fontSize: 12)); + return Material( key: ValueKey(hop.id), - contentPadding: EdgeInsets.zero, - leading: CircleAvatar( - radius: 14, - backgroundColor: scheme.primaryContainer, - child: Text( - '${index + 1}', - style: TextStyle(fontSize: 12, color: scheme.onPrimaryContainer), + color: highlighted ? scheme.primaryContainer : scheme.surfaceContainerLow, + child: ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 8), + visualDensity: singleLine + ? VisualDensity.compact + : VisualDensity.standard, + minVerticalPadding: singleLine ? 0 : 4, + leading: CircleAvatar( + radius: 16, + backgroundColor: scheme.primary, + child: Text( + '${index + 1}', + style: TextStyle(fontSize: 12, color: scheme.onPrimary), + ), ), - ), - title: Text( - name ?? l10n.pathEditor_unknownHop, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - subtitle: Text(hex), - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ - IconButton( - icon: const Icon(Icons.remove_circle_outline), - tooltip: l10n.pathEditor_removeHop, - constraints: const BoxConstraints(minWidth: 44, minHeight: 44), - onPressed: () => _removeHop(index), - ), - ReorderableDragStartListener( - index: index, - child: const Padding( - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 12), - child: Icon(Icons.drag_handle), + title: singleLine + ? Row( + children: [ + Expanded( + child: Text( + label, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(width: 8), + hash, + ], + ) + : Text(label, maxLines: 1, overflow: TextOverflow.ellipsis), + subtitle: singleLine ? null : hash, + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + icon: const Icon(Icons.remove_circle_outline), + tooltip: l10n.pathEditor_removeHop, + onPressed: () => _removeHop(index), ), - ), - ], + ReorderableDragStartListener( + index: index, + child: const SizedBox( + width: 48, + height: 48, + child: Icon(Icons.drag_handle), + ), + ), + ], + ), ), ); } @@ -246,16 +321,16 @@ class _PathEditorSheetState extends State { final full = _hops.length >= _maxHops; return ListTile( - contentPadding: EdgeInsets.zero, + contentPadding: const EdgeInsets.symmetric(vertical: 4), enabled: !full, leading: CircleAvatar( - radius: 16, + radius: 18, backgroundColor: isRepeater ? scheme.primaryContainer : scheme.secondaryContainer, child: Icon( isRepeater ? Icons.router : Icons.meeting_room, - size: 16, + size: 18, color: isRepeater ? scheme.onPrimaryContainer : scheme.onSecondaryContainer, @@ -263,13 +338,36 @@ class _PathEditorSheetState extends State { ), title: Text(contact.name, maxLines: 1, overflow: TextOverflow.ellipsis), subtitle: Text( - '${contact.typeLabel(l10n)} • ${PathHelper.formatHopHex(contact.publicKey.sublist(0, widget.pathHashByteWidth.clamp(1, contact.publicKey.length).toInt()))}', + '${contact.typeLabel(l10n)} • ${_contactHopHex(contact)}', + style: MeshTheme.mono(fontSize: 12), + ), + trailing: Icon( + Icons.add_circle_outline, + color: full ? scheme.outline : scheme.primary, ), - trailing: const Icon(Icons.add_circle_outline), onTap: full ? null : () => _addHop(contact), ); } + double _hopViewportHeight(double maxHeight, bool tight) { + if (_hops.isEmpty) return 0; + final scaler = MediaQuery.textScalerOf(context); + final rowExtent = tight + ? scaler.scale(56).clamp(56.0, 80.0) + : scaler.scale(76).clamp(72.0, 132.0); + final visibleRows = math.min(_hops.length, tight ? 2 : 3); + final wanted = visibleRows * rowExtent + 4; + // Header, hex field, search field, and the action row stay on screen. + // The hop viewport takes what is left, and never pushes the buttons + // up over the repeater list. + final chrome = tight ? 210.0 : 430.0; + final available = maxHeight - chrome; + if (available >= rowExtent) { + return math.min(wanted, available); + } + return math.max(0.0, available); + } + @override Widget build(BuildContext context) { final l10n = context.l10n; @@ -277,139 +375,208 @@ class _PathEditorSheetState extends State { final scheme = theme.colorScheme; final repeaters = _repeaters; - return Column( - children: [ - const SizedBox(height: 8), - Container( - width: 32, - height: 4, - decoration: BoxDecoration( - color: scheme.outlineVariant, - borderRadius: BorderRadius.circular(2), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(l10n.pathEditor_title, style: theme.textTheme.titleLarge), - Text( - l10n.pathEditor_hopCounter(_hops.length), - style: theme.textTheme.bodySmall?.copyWith( - color: scheme.onSurfaceVariant, - ), - ), - ], - ), - ), - Expanded( - child: ListView( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), - children: [ - if (_hops.isEmpty) - Padding( - padding: const EdgeInsets.symmetric(vertical: 12), - child: Text( - l10n.pathEditor_noHops, - style: theme.textTheme.bodySmall?.copyWith( - color: scheme.onSurfaceVariant, - ), - ), - ) - else - ReorderableListView.builder( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - buildDefaultDragHandles: false, - itemCount: _hops.length, - onReorderItem: _reorderHop, - itemBuilder: _hopTile, - ), - const Divider(), - const SizedBox(height: 8), - Text(l10n.pathEditor_addHops, style: theme.textTheme.titleSmall), - const SizedBox(height: 8), - TextField( - onChanged: (value) => setState(() => _search = value), - decoration: InputDecoration( - labelText: l10n.pathEditor_searchRepeaters, - prefixIcon: const Icon(Icons.search), - border: const OutlineInputBorder(), - isDense: true, - ), - ), - const SizedBox(height: 4), - if (repeaters.isEmpty) - Padding( - padding: const EdgeInsets.symmetric(vertical: 12), - child: Text( - l10n.path_noRepeatersFound, - style: theme.textTheme.bodySmall?.copyWith( - color: scheme.onSurfaceVariant, - ), - ), - ) - else - ...repeaters.map((c) => _repeaterTile(context, c)), - ExpansionTile( - tilePadding: EdgeInsets.zero, - title: Text( - l10n.pathEditor_advancedHex, - style: theme.textTheme.titleSmall, - ), + return LayoutBuilder( + builder: (context, constraints) { + final maxHeight = constraints.maxHeight.isFinite + ? constraints.maxHeight + : 640.0; + // Phone sheets and a keyboard-shrunk window use the shorter hop rows + // so the action buttons stay below the repeater list. + final compact = maxHeight < 680; + final hopHeight = _hopViewportHeight(maxHeight, compact); + + return Column( + children: [ + Padding( + padding: EdgeInsets.fromLTRB(16, compact ? 6 : 10, 16, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Padding( - padding: const EdgeInsets.only(bottom: 12), - child: TextField( - controller: _hexController, - onChanged: _onHexChanged, - textCapitalization: TextCapitalization.characters, - decoration: InputDecoration( - labelText: l10n.pathEditor_hexLabel, - helperText: _hexError == null - ? l10n.pathEditor_hexHelper - : null, - errorText: _hexError, - border: const OutlineInputBorder(), + Center( + child: Container( + width: 36, + height: 4, + decoration: BoxDecoration( + color: scheme.outline, + borderRadius: BorderRadius.circular(2), + ), + ), + ), + SizedBox(height: compact ? 4 : 12), + Text( + l10n.pathEditor_title, + style: theme.textTheme.titleMedium?.copyWith( + fontWeight: FontWeight.w700, + letterSpacing: -0.2, + ), + ), + Semantics( + liveRegion: true, + child: Text( + l10n.pathEditor_hopCounter(_hops.length), + style: theme.textTheme.bodySmall?.copyWith( + color: scheme.onSurfaceVariant, ), ), ), ], ), - ], - ), - ), - SafeArea( - top: false, - child: Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 16), - child: Row( - children: [ - Expanded( - child: TextButton( - style: TextButton.styleFrom( - minimumSize: const Size.fromHeight(48), - ), - onPressed: () => Navigator.pop(context), - child: Text(l10n.common_cancel), - ), - ), - const SizedBox(width: 12), - Expanded( - child: FilledButton( - style: FilledButton.styleFrom( - minimumSize: const Size.fromHeight(48), - ), - onPressed: _hexError != null ? null : _save, - child: Text(l10n.pathEditor_usePath), - ), - ), - ], ), - ), - ), - ], + Padding( + padding: EdgeInsets.fromLTRB(16, compact ? 4 : 10, 16, 0), + child: DecoratedBox( + decoration: BoxDecoration( + color: scheme.surfaceContainerLow, + borderRadius: BorderRadius.circular(MeshRadii.md), + border: Border.all(color: scheme.outlineVariant), + ), + child: _hops.isEmpty + ? Padding( + padding: const EdgeInsets.all(12), + child: Text( + l10n.pathEditor_noHops, + style: theme.textTheme.bodyMedium?.copyWith( + color: scheme.onSurfaceVariant, + ), + ), + ) + : SizedBox( + height: hopHeight, + child: ReorderableListView.builder( + scrollController: _hopScroll, + buildDefaultDragHandles: false, + padding: EdgeInsets.symmetric( + vertical: compact ? 0 : 4, + ), + itemCount: _hops.length, + onReorderItem: _reorderHop, + itemBuilder: (context, index) => + _hopTile(context, index, singleLine: compact), + ), + ), + ), + ), + Padding( + padding: EdgeInsets.fromLTRB(16, compact ? 6 : 16, 16, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (!compact) ...[ + Text( + l10n.pathEditor_advancedHex, + style: theme.textTheme.titleSmall, + ), + const SizedBox(height: 8), + ], + TextField( + key: const Key('path-editor-hex-field'), + controller: _hexController, + onChanged: _onHexChanged, + textCapitalization: TextCapitalization.characters, + style: MeshTheme.mono(fontSize: 14), + scrollPadding: EdgeInsets.zero, + decoration: InputDecoration( + labelText: l10n.pathEditor_hexLabel, + helperText: compact || _hexError != null + ? null + : l10n.pathEditor_hexHelper(_hashChars), + helperMaxLines: 3, + errorText: _hexError, + errorMaxLines: 3, + border: const OutlineInputBorder(), + isDense: compact, + ), + ), + ], + ), + ), + Padding( + padding: EdgeInsets.fromLTRB(16, compact ? 6 : 14, 16, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (!compact) ...[ + Text( + l10n.pathEditor_addHops, + style: theme.textTheme.titleSmall, + ), + const SizedBox(height: 8), + ], + TextField( + key: const Key('path-editor-search-field'), + onChanged: (value) => setState(() => _search = value), + scrollPadding: EdgeInsets.zero, + decoration: InputDecoration( + labelText: l10n.pathEditor_searchRepeaters, + prefixIcon: const Icon(Icons.search), + border: const OutlineInputBorder(), + isDense: compact, + ), + ), + ], + ), + ), + Expanded( + child: repeaters.isEmpty + ? Padding( + padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), + child: Align( + alignment: Alignment.topLeft, + child: Text( + l10n.path_noRepeatersFound, + style: theme.textTheme.bodyMedium?.copyWith( + color: scheme.onSurfaceVariant, + ), + ), + ), + ) + : ListView.builder( + key: const Key('path-editor-repeater-list'), + keyboardDismissBehavior: + ScrollViewKeyboardDismissBehavior.onDrag, + padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), + itemCount: repeaters.length, + itemBuilder: (context, index) => + _repeaterTile(context, repeaters[index]), + ), + ), + SafeArea( + top: false, + child: Padding( + padding: EdgeInsets.fromLTRB( + 16, + compact ? 4 : 8, + 16, + compact ? 4 : 16, + ), + child: Row( + children: [ + Expanded( + child: TextButton( + style: TextButton.styleFrom( + minimumSize: const Size.fromHeight(48), + ), + onPressed: () => Navigator.pop(context), + child: Text(l10n.common_cancel), + ), + ), + const SizedBox(width: 12), + Expanded( + child: FilledButton( + style: FilledButton.styleFrom( + minimumSize: const Size.fromHeight(48), + ), + onPressed: _hexError != null ? null : _save, + child: Text(l10n.pathEditor_usePath), + ), + ), + ], + ), + ), + ), + ], + ); + }, ); } } diff --git a/lib/widgets/share_contact_sheet.dart b/lib/widgets/share_contact_sheet.dart index df0549d7..c38c48d1 100644 --- a/lib/widgets/share_contact_sheet.dart +++ b/lib/widgets/share_contact_sheet.dart @@ -7,6 +7,7 @@ import '../l10n/contact_localization.dart'; import '../l10n/l10n.dart'; import '../models/contact.dart'; import '../theme/mesh_theme.dart'; +import '../utils/contact_search.dart'; import 'mesh_ui.dart'; /// Lets the user pick a saved contact (or themself) and appends the encoded @@ -50,14 +51,10 @@ class _ShareContactSheetState extends State<_ShareContactSheet> { final contacts = connector.contacts .where( - (c) => - c.publicKey.length == 32 && - (needle.isEmpty || c.name.toLowerCase().contains(needle)), + (c) => c.publicKey.length == 32 && matchesContactQuery(c, needle), ) .toList() - ..sort( - (a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()), - ); + ..sort((a, b) => compareContactQueryRank(a, b, needle)); final selfName = connector.selfName ?? ''; final showSelf = selfKey != null && diff --git a/test/utils/contact_search_test.dart b/test/utils/contact_search_test.dart new file mode 100644 index 00000000..d2d1cff4 --- /dev/null +++ b/test/utils/contact_search_test.dart @@ -0,0 +1,109 @@ +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/connector/meshcore_protocol.dart'; +import 'package:meshcore_open/models/contact.dart'; +import 'package:meshcore_open/utils/contact_search.dart'; + +Contact _contact( + String name, + List key, { + int type = advTypeRepeater, + DateTime? lastSeen, +}) { + return Contact( + publicKey: Uint8List.fromList(key), + name: name, + type: type, + pathLength: -1, + path: Uint8List(0), + lastSeen: lastSeen ?? DateTime.fromMillisecondsSinceEpoch(0), + ); +} + +List _ranked(List contacts, String query) { + final matches = contacts.where((c) => matchesContactQuery(c, query)).toList() + ..sort((a, b) => compareContactQueryRank(a, b, query)); + return matches.map((c) => c.name).toList(); +} + +void main() { + final contacts = [ + _contact('100 Acre', [0x11, 0x22, 0x33, 0x44]), + _contact('Acreage North', [0x33, 0x44, 0x55, 0x66]), + _contact('My Acre Site', [0x55, 0x66, 0x77, 0x88]), + _contact('2E0HQR-R', [0x2E, 0x0A, 0x1B, 0x2C]), + _contact('CR1', [0x60, 0x60, 0xAB, 0xCD]), + _contact('Node 6060', [0x01, 0x02, 0x03, 0x04]), + _contact('6060 Hub', [0x0A, 0x0B, 0x0C, 0x0D]), + ]; + + test('name prefixes rank before other substring matches', () { + expect(_ranked(contacts, 'acre'), [ + 'Acreage North', + '100 Acre', + 'My Acre Site', + ]); + }); + + test('prefix matches stay alphabetical among themselves', () { + final extra = [ + _contact('Acreage North', [0x01]), + _contact('Acre Beacon', [0x02]), + ]; + expect(_ranked(extra, 'acre'), ['Acre Beacon', 'Acreage North']); + }); + + test('a hop hash matches when the name does not', () { + expect(matchesContactQuery(contacts[4], '6060'), isTrue); + expect(matchesContactQuery(contacts[4], '60'), isTrue); + expect(matchesContactQuery(contacts[4], '6060abcd'), isTrue); + expect(matchesContactQuery(contacts[4], '6061'), isFalse); + expect(_ranked(contacts, '6060'), ['6060 Hub', 'Node 6060', 'CR1']); + }); + + test('hash search accepts 0x, spaces, and angle brackets', () { + expect(_ranked(contacts, '0x6060'), ['CR1']); + expect(_ranked(contacts, '60 60'), ['CR1']); + expect(_ranked(contacts, '<6060>'), ['CR1']); + }); + + test('a single hex digit does not match every key', () { + expect(matchesContactQuery(contacts[4], '6'), isFalse); + }); + + test('an empty query matches every contact and keeps the tie-break', () { + final timed = [ + _contact('B', [0x01], lastSeen: DateTime.utc(2024, 1, 2)), + _contact('A', [0x02], lastSeen: DateTime.utc(2024, 1, 3)), + ]; + timed.sort( + (a, b) => compareContactQueryRank( + a, + b, + '', + (a, b) => b.lastSeen.compareTo(a.lastSeen), + ), + ); + expect(timed.map((c) => c.name), ['A', 'B']); + }); + + test('tie-break applies inside a rank, not across ranks', () { + final olderPrefix = _contact('Acre Older', [ + 0x01, + ], lastSeen: DateTime.utc(2020)); + final newerSubstring = _contact('My Acre', [ + 0x02, + ], lastSeen: DateTime.utc(2024)); + final ranked = [newerSubstring, olderPrefix] + ..sort( + (a, b) => compareContactQueryRank( + a, + b, + 'acre', + (a, b) => b.lastSeen.compareTo(a.lastSeen), + ), + ); + expect(ranked.map((c) => c.name), ['Acre Older', 'My Acre']); + }); +} diff --git a/test/widgets/path_editor_sheet_test.dart b/test/widgets/path_editor_sheet_test.dart new file mode 100644 index 00000000..79ecf6af --- /dev/null +++ b/test/widgets/path_editor_sheet_test.dart @@ -0,0 +1,199 @@ +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/connector/meshcore_protocol.dart'; +import 'package:meshcore_open/l10n/app_localizations.dart'; +import 'package:meshcore_open/models/contact.dart'; +import 'package:meshcore_open/widgets/path_editor_sheet.dart'; + +Contact _repeater(String name, List prefix) { + final key = Uint8List(32); + for (var i = 0; i < prefix.length; i++) { + key[i] = prefix[i]; + } + return Contact( + publicKey: key, + name: name, + type: advTypeRepeater, + pathLength: -1, + path: Uint8List(0), + lastSeen: DateTime.fromMillisecondsSinceEpoch(0), + ); +} + +final _contacts = [ + _repeater('100 Acre', [0x11, 0x22]), + _repeater('Acreage North', [0x33, 0x44]), + _repeater('My Acre Site', [0x55, 0x66]), + _repeater('2E0HQR-R', [0x2E, 0x0A]), + _repeater('CR1', [0x60, 0x60]), + for (var i = 0; i < 24; i++) _repeater('Repeater $i', [0xA0, i]), +]; + +Future _pumpSheet( + WidgetTester tester, { + Size size = const Size(400, 700), + double keyboard = 0, + List initialPath = const [], +}) async { + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + await tester.pumpWidget( + MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: MediaQuery( + data: MediaQueryData( + size: size, + viewInsets: EdgeInsets.only(bottom: keyboard), + ), + child: Scaffold( + body: SizedBox( + width: size.width, + height: size.height - keyboard, + child: PathEditorSheet( + availableContacts: _contacts, + initialPath: initialPath, + pathHashByteWidth: 2, + ), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); +} + +List _repeaterNames(WidgetTester tester) { + return tester + .widgetList( + find.descendant( + of: find.byKey(const Key('path-editor-repeater-list')), + matching: find.byType(Text), + ), + ) + .map((text) => text.data) + .whereType() + .where((text) => !text.contains('•')) + .toList(); +} + +void main() { + testWidgets('prefix matches are listed before other substring matches', ( + tester, + ) async { + await _pumpSheet(tester); + await tester.enterText( + find.byKey(const Key('path-editor-search-field')), + 'acre', + ); + await tester.pumpAndSettle(); + + final visible = _repeaterNames(tester); + expect(visible.first, 'Acreage North'); + expect(visible[1], '100 Acre'); + await tester.scrollUntilVisible( + find.text('My Acre Site'), + 80, + scrollable: find.descendant( + of: find.byKey(const Key('path-editor-repeater-list')), + matching: find.byType(Scrollable), + ), + ); + expect(find.text('My Acre Site'), findsOneWidget); + }); + + testWidgets('search matches a hop hash the name does not contain', ( + tester, + ) async { + await _pumpSheet(tester); + await tester.enterText( + find.byKey(const Key('path-editor-search-field')), + '6060', + ); + await tester.pumpAndSettle(); + + expect(find.text('No repeaters or room servers found.'), findsNothing); + expect(_repeaterNames(tester), ['CR1']); + }); + + testWidgets('hex entry is reachable without scrolling the repeater list', ( + tester, + ) async { + await _pumpSheet(tester, size: const Size(400, 900)); + expect( + find.byKey(const Key('path-editor-hex-field')).hitTestable(), + findsOneWidget, + ); + expect(find.text('Hex prefixes'), findsOneWidget); + expect( + find.text('4 hex characters per hop, separated by commas'), + findsOneWidget, + ); + }); + + testWidgets('an added hop stays fully visible with the keyboard open', ( + tester, + ) async { + await _pumpSheet( + tester, + size: const Size(390, 640), + keyboard: 320, + initialPath: [0x60, 0x60], + ); + + final tile = find.ancestor( + of: find.byIcon(Icons.remove_circle_outline), + matching: find.byType(ListTile), + ); + expect(tile.hitTestable(), findsOneWidget); + final title = tester.getRect(find.text('Build Path')); + final hopRect = tester.getRect(tile); + final sheet = tester.getRect(find.byType(PathEditorSheet)); + expect(hopRect.top, greaterThanOrEqualTo(title.bottom)); + expect(hopRect.bottom, lessThanOrEqualTo(sheet.bottom)); + expect(hopRect.height, greaterThanOrEqualTo(48)); + expect(find.text('CR1').hitTestable(), findsWidgets); + expect(find.text('6060').hitTestable(), findsWidgets); + expect( + find.byKey(const Key('path-editor-hex-field')).hitTestable(), + findsOneWidget, + ); + expect(tester.takeException(), isNull); + }); + + testWidgets('action buttons stay below the repeater list on a short sheet', ( + tester, + ) async { + await _pumpSheet( + tester, + size: const Size(400, 560), + initialPath: [0x60, 0x60, 0x11, 0x22], + ); + + expect(tester.takeException(), isNull); + final button = tester.getRect(find.text('Use this path')); + final list = tester.getRect( + find.byKey(const Key('path-editor-repeater-list')), + ); + expect(button.top, greaterThanOrEqualTo(list.bottom - 1)); + }); + + testWidgets('tapping a repeater adds a visible hop', (tester) async { + await _pumpSheet(tester); + await tester.enterText( + find.byKey(const Key('path-editor-search-field')), + '6060', + ); + await tester.pumpAndSettle(); + await tester.tap(find.widgetWithText(ListTile, 'CR1')); + await tester.pumpAndSettle(); + + expect(find.text('1 of 64 hops'), findsOneWidget); + expect(find.byIcon(Icons.remove_circle_outline), findsOneWidget); + expect(find.text('CR1').hitTestable(), findsWidgets); + }); +}