Skip to content

refactor(ui): single text-editing helper for the main page (R23)#106

Merged
stormer78 merged 2 commits into
mainfrom
r23-text-edit-helper
Jun 12, 2026
Merged

refactor(ui): single text-editing helper for the main page (R23)#106
stormer78 merged 2 commits into
mainfrom
r23-text-edit-helper

Conversation

@stormer78

Copy link
Copy Markdown
Contributor

Problem

The Char(c) push / Backspace pop / clone / send-Action sequence was re-implemented 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

  • 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; deliberately not tui-input, which would change behavior).
  • 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 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

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>
@stormer78 stormer78 requested a review from a team as a code owner June 12, 2026 03:31
@stormer78 stormer78 merged commit f59eaf4 into main Jun 12, 2026
11 of 13 checks passed
@stormer78 stormer78 deleted the r23-text-edit-helper branch June 12, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant