Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@shkmv
Copy link

@shkmv shkmv commented Dec 16, 2025

Sidebar toggle hotkeys (Ctrl+B, Ctrl+Shift+B, Ctrl+, Ctrl+4) were not working in insert mode and when sidebar had focus. Added handling for Action::ToggleSidebar in insert mode and direct key handling in handle_sidebar_key function.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added keyboard shortcuts to toggle the sidebar: Ctrl+B, Ctrl+Shift+B, Ctrl+, and Ctrl+4.
    • Added quick access to query history.
    • Improved grid cell click detection for more accurate selection of headers and body cells.

✏️ Tip: You can customize this high-level summary in your review settings.

fcoury and others added 3 commits December 16, 2025 10:31
…ry keys

Add multiple keybinding alternatives for sidebar toggle (Ctrl+Shift+B, Ctrl+\, Ctrl+4) to address terminal compatibility issues. Opening the sidebar now automatically focuses the Schema section.

Enable cell editing for tables without a detected primary key by using a ctid-based WHERE clause fallback that matches the first row by all column values. Validate that updates affect exactly 1 row and provide clear feedback when ambiguous.

Improve query parser to handle quoted identifiers, schema prefixes, and complex SELECT statements when extracting table names.

Add --debug-keys flag to help troubleshoot keybinding issues in different terminals.
Sidebar toggle hotkeys (Ctrl+B, Ctrl+Shift+B, Ctrl+\, Ctrl+4) were not
working in insert mode and when sidebar had focus. Added handling for
Action::ToggleSidebar in insert mode and direct key handling in
handle_sidebar_key function.
@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

Adds global keyboard shortcuts (Ctrl+B, Ctrl+Shift+B, Ctrl+, Ctrl+4) for sidebar visibility toggling with automatic focus management. Introduces new Action enum variants (ToggleSidebar, ShowHistory), implements grid mouse target calculation to distinguish header vs. body cell clicks, and refactors SQL generation parameter handling.

Changes

Cohort / File(s) Summary
Keyboard Shortcuts & Sidebar Toggle
crates/tsql/src/app/app.rs
Adds four new global keyboard shortcuts to toggle sidebar visibility and manage focus transitions. Implements Action::ToggleSidebar handler to toggle sidebar state and route focus between Query and Schema components.
Action Enum Extensions
crate::config (Action enum)
Adds two new action variants: ToggleSidebar (sidebar visibility control) and ShowHistory (history picker launch).
Grid Mouse Target Helper
crates/tsql/src/app/app.rs
Introduces grid_mouse_target function with associated tests to determine whether a mouse click targets a grid header or body cell, accounting for row number columns and variable column widths.
SQL Generation Refactor
crates/tsql/src/app/app.rs
Refactors build_update_where_clause to pass original_value.as_str() directly instead of wrapping in an additional reference.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas requiring extra attention:

  • Verification that all four keyboard shortcuts are correctly bound and prioritized in the keymap without conflicts
  • Focus transition logic in Action::ToggleSidebar handler (sidebar ↔ Query/Schema) under different modal states
  • grid_mouse_target function logic and test coverage, especially edge cases around row number columns and dynamic column widths
  • Confirmation that ShowHistory action is wired consistently with existing modal/picker patterns

Possibly related PRs

Poem

🐰 With Ctrl+B, the sidebar dances free,
Now Ctrl+Shift+B brings it back to me!
Mouse clicks are measured, headers gleam,
Focus flows—a UI dream! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: enabling sidebar toggle hotkeys to work in insert mode and improving sidebar focus behavior, which aligns with the PR's primary objective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/tsql/src/app/app.rs (2)

2554-2575: Sidebar Ctrl+B / Ctrl+\ handling in handle_sidebar_key looks correct but duplicates toggle logic

The new arms correctly ensure Ctrl+B / Ctrl+Shift+B / Ctrl+\ / Ctrl+4 close the sidebar and return focus to the query even when the sidebar has focus, including in insert mode (since this path is independent of Mode). Note that in Normal mode Ctrl+Shift+B and Ctrl+\ are already handled earlier in on_key, so these arms primarily cover Ctrl+B and all four chords when mode != Mode::Normal, which is consistent with the PR intent.

You now have essentially identical sidebar-toggling logic in several places (global Normal-mode handler, grid Action::ToggleSidebar, editor Normal/Insert Action::ToggleSidebar, and here). Consider extracting a small fn toggle_sidebar(&mut self) helper (or toggle_sidebar_from_sidebar vs. generic) to keep behavior consistent and reduce future drift.


5722-5829: ** targeted clippy::too_many_arguments allow on grid_mouse_target is acceptable, but consider bundling args**

Adding #[allow(clippy::too_many_arguments)] on grid_mouse_target is a pragmatic way to keep cargo clippy -D warnings happy for a UI helper that naturally needs several parameters (position, viewport, offsets, widths). Given the function’s focused scope and existing tests around grid_mouse_target, this is reasonable.

Longer-term, you might consider grouping some of the related parameters (e.g., row/col offsets + counts + show_row_numbers + col_widths) into a small struct to remove the need for the allow and make call sites a bit clearer, but that’s optional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6ce2543 and a3b9f89.

📒 Files selected for processing (1)
  • crates/tsql/src/app/app.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Run cargo fmt --all to format the code before committing changes
Run cargo clippy --all --all-targets -- -D warnings to check for lints and fix them before pushing changes

**/*.rs: Use rustfmt with default settings as the source of truth for code formatting in Rust files
Use snake_case for function and module names in Rust
Use CamelCase for type and trait names in Rust
Use SCREAMING_SNAKE_CASE for constant names in Rust
Keep changes focused and prefer small, composable helper functions over large UI/app methods
Place unit tests colocated with code using #[cfg(test)] modules for pure logic testing

Files:

  • crates/tsql/src/app/app.rs
🧠 Learnings (1)
📚 Learning: 2025-12-14T16:15:31.051Z
Learnt from: CR
Repo: fcoury/tsql PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-14T16:15:31.051Z
Learning: Applies to **/*.rs : Keep changes focused and prefer small, composable helper functions over large UI/app methods

Applied to files:

  • crates/tsql/src/app/app.rs
🧬 Code graph analysis (1)
crates/tsql/src/app/app.rs (1)
crates/tsql/src/ui/grid.rs (2)
  • row (827-829)
  • row (851-853)
🔇 Additional comments (2)
crates/tsql/src/app/app.rs (2)

3243-3251: build_update_where_clause call now correctly passes Option<&str>

Switching to Some(original_value.as_str()) matches the edited_original_value: Option<&str> parameter type and avoids unnecessary reference nesting. The borrow is confined to the call site and doesn’t outlive original_value, so lifetimes are sound. No further changes needed here.


4529-4543: Insert-mode handling for ToggleSidebar and ShowHistory is consistent and well‑scoped

Wiring Action::ToggleSidebar and Action::ShowHistory into the Insert-mode branch of handle_editor_key brings Insert behavior in line with Normal mode: the sidebar toggle mirrors the existing implementations (using focus_schema() when opening, returning focus to Query when closing from a sidebar focus), and history opens via open_history_picker(). Early returns ensure these actions don’t fall through to self.editor.input(key).

This cleanly fixes the missing Insert-mode bindings without unintended side effects.

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.

2 participants