refactor(ui): single text-editing helper for the main page (R23)#106
Merged
Conversation
The `Char(c)` push / `Backspace` pop / clone / send-Action sequence was re-implemented 8× across the main page's key handlers, and the Export/Import settings arms were ~68 lines of character-identical code. Add a free `edit_text(code, current) -> Option<String>` helper with append-only semantics (printable char appends, Backspace pops the last char, no cursor — matching the prior inline editors exactly) and collapse the 8 Backspace/Char arm-pairs into one arm each. Field-indexed sites (relationship did/alias/reason; protection passphrase/confirm) write their buffer-selection logic once instead of duplicating it across two arms. Extract `handle_config_form_key(key, active, path, make_submit)` to unify the Export and Import arms, parameterized only by the differing submit Action (`ExportConfig` vs `ImportConfig`). Behavior is identical: every arm emits the same Action variant/field/value and returns the same bool; secure buffers (protection + config-import passphrase) still emit only their length, never the secret; Backspace on an empty buffer stays a no-op. `main/mod.rs`: 1766 → 1686 lines. Verified by a code-reviewer pass (all 8 sites + Export/Import confirmed behavior-equivalent, no secret leak). Gate: cargo fmt --all, clippy --workspace --all-targets -D warnings (incl. --features openpgp-card), cargo test -p openvtc (96 passed) — all green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
Char(c)push /Backspacepop / clone / send-Action sequence was re-implemented 8× across the main page's key handlers (ui/pages/main/mod.rs), and the Export/Import settings arms were ~68 lines of character-identical code.Fix
edit_text(code, current) -> Option<String>helper with append-only semantics (printable char appends, Backspace pops the last char, no cursor — matching the prior inline editors exactly; deliberately nottui-input, which would change behavior).handle_config_form_key(key, active, path, make_submit)to unify the Export and Import arms, parameterized only by the differing submit Action (ExportConfigvsImportConfig).Behavior preservation
Identical behavior: every arm emits the same Action variant/field/value and returns the same bool. Secure buffers (protection + config-import passphrase) still emit only their
len(), never the secret. Backspace on an empty buffer stays a no-op.main/mod.rs: 1766 → 1686 lines.A code-reviewer pass verified all 8 sites + the Export/Import unification as behavior-equivalent, with the secret-no-leak check passing at both secure sites.
Gate
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings(incl.--features openpgp-card),cargo test -p openvtc(96 passed) — all green.🤖 Generated with Claude Code