-
Notifications
You must be signed in to change notification settings - Fork 3
fix(tui): improve autocomplete popup positioning and width calculation #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Greptile OverviewGreptile SummaryFixed two autocomplete popup issues: prevents off-screen rendering at the top by checking if there's room above before positioning, and calculates width based on filtered items instead of all items to prevent unnecessarily wide popups. Key Changes
Potential Issue
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/cortex-tui/src/widgets/autocomplete.rs | Improved popup positioning with screen bounds check and fixed width calculation to use filtered items - minor edge case with bottom overflow |
Sequence Diagram
sequenceDiagram
participant User
participant Widget as AutocompletePopup
participant State as AutocompleteState
participant Screen as Terminal Screen
User->>Widget: Trigger autocomplete
Widget->>State: Check visible_items()
State-->>Widget: Return filtered items slice
Widget->>Widget: calculate_dimensions()
Note over Widget: Use visible_items() for width<br/>Calculate height from item count
Widget->>Screen: Check area.y >= height?
alt Room above input
Widget->>Screen: Position at area.y - height
else No room above
Widget->>Screen: Position at area.bottom()
Note over Widget,Screen: May overflow if not enough<br/>room below either
end
Widget->>Screen: Render popup with items
Widget->>Widget: render_item() for each visible item
Screen-->>User: Display autocomplete popup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
| let y = if area.y >= height { | ||
| // Enough room above - position popup above the input | ||
| area.y.saturating_sub(height) | ||
| } else { | ||
| // Not enough room above - position popup below the input | ||
| area.bottom() | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positioning below doesn't check screen bounds - popup may overflow bottom edge
when area.y < height, popup positions at area.bottom() without verifying if area.bottom() + height exceeds terminal height
| let y = if area.y >= height { | |
| // Enough room above - position popup above the input | |
| area.y.saturating_sub(height) | |
| } else { | |
| // Not enough room above - position popup below the input | |
| area.bottom() | |
| }; | |
| let y = if area.y >= height { | |
| // Enough room above - position popup above the input | |
| area.y.saturating_sub(height) | |
| } else { | |
| // Not enough room above - position popup below the input | |
| // Note: caller should ensure area.bottom() + height doesn't exceed screen bounds | |
| area.bottom() | |
| }; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cortex-tui/src/widgets/autocomplete.rs
Line: 210:216
Comment:
positioning below doesn't check screen bounds - popup may overflow bottom edge
when `area.y < height`, popup positions at `area.bottom()` without verifying if `area.bottom() + height` exceeds terminal height
```suggestion
let y = if area.y >= height {
// Enough room above - position popup above the input
area.y.saturating_sub(height)
} else {
// Not enough room above - position popup below the input
// Note: caller should ensure area.bottom() + height doesn't exceed screen bounds
area.bottom()
};
```
How can I resolve this? If you propose a fix, please make it concise.… prevention This PR consolidates the following fixes: - #38: Prevent usize to u16 overflow in interactive renderer - #42: Prevent usize to u16 overflow in card count displays - #58: Fix cursor positioning and underflow in selection list - #59: Fix mention popup positioning and Unicode width calculation - #60: Improve autocomplete popup positioning and width calculation - #64: Prevent underflow in dropdown navigation and scroll calculations - #66: Prevent panic in HelpBrowserState when sections empty All changes target the TUI components to improve robustness: - Added saturating casts for u16 conversions - Fixed cursor positioning calculations - Added bounds checking for empty sections - Improved Unicode width handling for popups
|
Consolidated into #69 - fix(tui): consolidated TUI fixes for overflow, positioning, and panic prevention |
Summary
Fixes #5199 and #5193 - Autocomplete popup issues.
Problems
Solution
Added screen bounds check for positioning and use filtered items for width.