Refactor UI: Fix bugs, optimize rendering, and reduce tech debt#71
Conversation
leszek3737
commented
Jun 11, 2026
- Fix off-by-one in confirm dialog file list and capacity
- Fix scrollbar/text desync for >65535 lines in help dialog
- Fix CJK/emoji capacity bug in input dialog (bytes vs columns)
- Fix control char width counting in text dialog (unwrap_or(0))
- Fix overflow in visual_row_to_logical (checked_add)
- Fix scroll_right max_offset when effective_width == 0
- Fix viewer render heights bounds check (panic prevention)
- Fix viewer loader Drop blocking event thread (detach instead of join)
- Fix viewer open.rs capacity mismatch (MAX_VIEW_SIZE + 1)
- Fix search overlapping/non-overlapping inconsistency
- Fix toggle.rs recomputing line_offsets for Image mode
- Extract helpers: collect_graphemes_up_to_width, build_visible, styled_padded_line, HelpGeometry, centered_paragraph, viewer_title, write_line_number, CancellableLoader, ViewerRenderCache
- Consolidate mime constants to shared app/mime.rs
- Simplify theme macro, remove deprecated icon_theme()
- Add reusable buffers for panel rendering (~50 allocs/frame saved)
- Pipe read limit 50MiB, join timeout 2s in viewer loader
- Extract dialog tests from mod.rs to tests.rs
- Strengthen test assertions, add missing negative/edge-case tests
- 1011 tests pass, clippy clean, release build OK
…cross 24 files - Fix off-by-one in confirm dialog file list and capacity - Fix scrollbar/text desync for >65535 lines in help dialog - Fix CJK/emoji capacity bug in input dialog (bytes vs columns) - Fix control char width counting in text dialog (unwrap_or(0)) - Fix overflow in visual_row_to_logical (checked_add) - Fix scroll_right max_offset when effective_width == 0 - Fix viewer render heights bounds check (panic prevention) - Fix viewer loader Drop blocking event thread (detach instead of join) - Fix viewer open.rs capacity mismatch (MAX_VIEW_SIZE + 1) - Fix search overlapping/non-overlapping inconsistency - Fix toggle.rs recomputing line_offsets for Image mode - Extract helpers: collect_graphemes_up_to_width, build_visible, styled_padded_line, HelpGeometry, centered_paragraph, viewer_title, write_line_number, CancellableLoader, ViewerRenderCache - Consolidate mime constants to shared app/mime.rs - Simplify theme macro, remove deprecated icon_theme() - Add reusable buffers for panel rendering (~50 allocs/frame saved) - Pipe read limit 50MiB, join timeout 2s in viewer loader - Extract dialog tests from mod.rs to tests.rs - Strengthen test assertions, add missing negative/edge-case tests - 1011 tests pass, clippy clean, release build OK
There was a problem hiding this comment.
Sorry @leszek3737, your pull request is larger than the review limit of 150000 diff characters
There was a problem hiding this comment.
Code Review
This pull request introduces significant refactoring and performance optimizations across the UI and viewer modules, notably extracting a ViewerRenderCache to isolate render-specific caches, consolidating MIME type constants, and introducing a CancellableLoader abstraction to reduce duplication. It also replaces tuple-based geometries with structured types, optimizes string formatting with reusable scratch buffers, and migrates inline tests to dedicated test files. Feedback on these changes highlights a debug_assert! in the search module that will always panic in debug builds when handling expanded lowercase characters, as well as a potential layout overflow in the confirmation dialog when the visible height is extremely small.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
PR Review: Refactor UI — Fix bugs, optimize rendering, reduce tech debtOverall Assessment: High quality PR. Well-structured refactoring with genuine bug fixes, good test coverage, and clean elimination of tech debt. No blocking issues found.Genuine Bug Fixes (All Correct)
Code Quality & DesignStrengths:
Observations / Non-blocking suggestions:
Project Convention Compliance
SummaryThis is a well-executed refactoring PR. The bug fixes are real and address edge cases (CJK width, overflow, event thread blocking). The structural changes (render cache, CancellableLoader, theme macro simplification, mime consolidation) all reduce tech debt without introducing new complexity. Test coverage is strong with 385 new lines of tests extracted and expanded. No blocking issues — approve. |
Greptile SummaryThis PR is a broad refactor and bug-fix sweep across the viewer, dialogs, panels, and theme layers. It extracts
Confidence Score: 2/5Not safe to merge as-is: two rendering bugs ship on every frame, and search produces wrong results for all multi-character queries. Three independent issues affect core, always-exercised paths: the status bar unconditionally appends a stale scratch buffer on every frame (doubling the right-side summary for every active panel), the text-mode and hex-fallback search both advance by one character instead of one match-length (producing duplicate/spurious match highlights for any query longer than one character), and the wrapped_line_count control-character fix inverts the intended behaviour. A fourth issue — toggle_hex_mode skipping clear_search_results for non-binary files — can leave a stale current_match index pointing past the end of the new match list after a mode toggle. The refactor work itself is well-structured and the underlying fixes for scroll overflow, the help-dialog desync, and the confirm off-by-one are correct. src/ui/panels/mod.rs (status bar scratch-buffer reuse), src/ui/viewer/search.rs (search stride in text and hex fallback), src/ui/dialogs/text.rs (wrapped_line_count control-char width), src/ui/viewer/toggle.rs (clear_search_results scope narrowed too far) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ViewerLoader::start] -->|CancellableLoader::spawn| B[background thread]
B -->|ViewerState::open_with_cancel| C{file type}
C -->|archive| D[new_text_listing]
C -->|image| E[new_normal - Image mode]
C -->|text| F[new_normal - Text mode]
C -->|binary| G[new_normal - Hex mode]
D & E & F & G --> H[ViewerState with ViewerRenderCache]
H --> I[visual_heights RefCell]
H --> J[visual_offsets RefCell]
H --> K[cached_line_num_col_width Cell]
H --> L[cached_image_text Option]
subgraph panel_render[Panel status bar - BUG]
P1[panel_status_summary into scratch] --> P2[right_width computed]
P2 --> P3[entry info written into out]
P3 -->|scratch still appended unconditionally| P4[duplicate right summary]
end
subgraph search_flow[Search - BUG]
S1[query] --> S2[clear_search_results]
S2 --> S3[find match in lower_buf]
S3 -->|advance by 1 char not query len| S3
end
|
- search.rs: fix debug_assert! that always panics for expanded lowercase (ß→ss) - confirm.rs: guard against layout overflow when max_visible <= 1 - panels/mod.rs: fix status bar duplicating scratch content after padding - toggle.rs: move clear_search_results outside binary-only guard to prevent stale search state when toggling hex mode on non-binary text files
PR Review: Refactor UI — Fix bugs, optimize rendering, reduce tech debtOverall Assessment: Approve. This is a well-structured refactoring PR with genuine bug fixes, clean structural improvements, and strong test coverage. All 226 tests pass, clippy is clean.Evaluation of Flagged Issues from Other ReviewersSeveral P1 claims from automated reviewers are false positives. I verified each against the actual code:
Genuine Design Observation (Non-blocking)
Verified Bug Fixes (All Correct)
Structural Improvements
Project Convention Compliance
SummaryHigh-quality refactoring PR. All flagged "P1 bugs" from other reviewers are false positives. The bug fixes are genuine and address real edge cases. The structural changes reduce tech debt without introducing new complexity. Recommended merge. |

