Skip to content

Conversation

@ysthakur
Copy link
Member

Fixes #972

Description

When the longest suggestion in a columnar menu exceeds the screen width, all suggestions will take up more than 1 line. None of the suggestion values will be truncated, and even short suggestion values will be padded to the same length as the longest suggestion. This PR fixes that by truncating values to the screen width.

This PR is just a fix, so I didn't want to change behavior too much, but in the future, we might want to consider basing the padding not on the longest suggestion, but the longest visible suggestion (when there are descriptions). When there aren't descriptions, the number of columns would probably have to be based on the longest suggestion overall, since it might be confusing if you scroll down and the number of columns changes.

Screenshots

Here's an example of how the values get truncated (note that these suggestions have descriptions, they're just not shown because the longest suggestion is too long):

image

When the longest suggestion isn't too long, you see the descriptions (in this PR, I changed it so that they end in "..." when truncated):
image

And this is what you get without descriptions:
image

///
/// If `s` is longer than `max_width`, the resulting string will end in "..."
/// and have width at most `max_width`.
pub(crate) fn truncate_no_ansi(s: &str, max_width: usize) -> Cow<str> {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's named truncate_no_ansi because I intend to add a truncate_with_ansi helper that truncates strings that do contain ANSI escapes (so it must ignore the ANSI escapes)

} else {
suggestion.value.clone()
};
let string = truncate_no_ansi(&suggestion.value, max_string_width);
Copy link
Member Author

Choose a reason for hiding this comment

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

I used the truncation helper here because the original code looks at number of chars rather than width

@blindFS
Copy link
Contributor

blindFS commented Nov 17, 2025

Nice! Works well for me.

@blindFS
Copy link
Contributor

blindFS commented Nov 17, 2025

A separated minor issue of IDE menu:

The display is a bit off on some cherry-picked terminal width values, on the edge of showing/hiding the description window.
image

if let Ok(position) = cursor::position() {
self.prompt_start_row = position.1;
self.just_resized = true;
#[cfg(not(test))]
Copy link
Member Author

Choose a reason for hiding this comment

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

Couldn't figure how to mock the Painter struct with mockall so I figured this was easier

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.

Columnar completion menu can make prompt disappear in narrow terminals

2 participants