Skip to content

[BUG][v0.0.7] model_picker.rs: fix legend overlap + UTF-8 caret misalignment#222

Open
sungdark wants to merge 1 commit intoCortexLM:mainfrom
sungdark:fix/model-picker-overlap-caret
Open

[BUG][v0.0.7] model_picker.rs: fix legend overlap + UTF-8 caret misalignment#222
sungdark wants to merge 1 commit intoCortexLM:mainfrom
sungdark:fix/model-picker-overlap-caret

Conversation

@sungdark
Copy link
Copy Markdown

Fix: model_picker narrow-terminal overlap and UTF-8 caret misalignment

Bug A — Legend / help row overlap

File: src/cortex-tui/src/widgets/model_picker.rs
Function: render_help_bar

help_x = area.right().saturating_sub(help.len() + 1) has no guard to stay to the right of the legend. For narrow terminals (50-60 cols) the shortcut string overwrites the legend, producing a garbled footer.

Fix: Check that help_x > legend_right + 1 before rendering the help string. When width is insufficient only the legend (* / +) is shown — no overlap.

Bug B — Search caret uses byte length instead of display width

File: src/cortex-tui/src/widgets/model_picker.rs
Function: render_search_bar

cursor_x = x + 3 + self.state.search_query.len() uses str::len() which counts UTF-8 bytes. Multi-byte characters (CJK, emoji) cause the caret to misalign with the visible text.

Fix: Use UnicodeWidthStr::width() (already a workspace dependency) instead of byte length.

Testing

  • Bug A: open model picker in a terminal narrowed to ~55 cols — legend and hints no longer collide.
  • Bug B: type CJK/emoji in search — caret aligns correctly with the last visible character.

Bounty

Issue: PlatformNetwork/bounty-challenge#40176

Fix two bugs in cortex-tui model picker (issue #40176):

A) Legend/help row overlap (narrow terminals):
  render_help_bar now checks that help_x > legend_right + 1 before
  rendering the shortcut string. When the terminal is too narrow the
  legend (* / +) renders alone — no garbled collision.

B) Search caret uses byte length instead of display width:
  render_search_bar now uses UnicodeWidthStr::width() instead of
  .len() so CJK characters and emoji don't misplace the caret.

Both fixes are conservative; existing behaviour is preserved when
there is enough terminal space.
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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