fix: multiline command does not honour max_preview_height (#2624)

Resolves #2610
This commit is contained in:
Matthew Berryman
2025-03-12 20:53:48 +10:30
committed by GitHub
parent 8274e727cb
commit a56d0cfd5e

View File

@@ -540,8 +540,27 @@ impl State {
&& !results.is_empty() && !results.is_empty()
{ {
let length_current_cmd = results[selected].command.len() as u16; let length_current_cmd = results[selected].command.len() as u16;
// calculate the number of newlines in the command
let num_newlines = results[selected]
.command
.chars()
.filter(|&c| c == '\n')
.count() as u16;
if num_newlines > 0 {
std::cmp::min(
settings.max_preview_height,
results[selected]
.command
.split('\n')
.map(|line| {
(line.len() as u16 + preview_width - 1 - border_size)
/ (preview_width - border_size)
})
.sum(),
) + border_size * 2
}
// The '- 19' takes the characters before the command (duration and time) into account // The '- 19' takes the characters before the command (duration and time) into account
if length_current_cmd > preview_width - 19 { else if length_current_cmd > preview_width - 19 {
std::cmp::min( std::cmp::min(
settings.max_preview_height, settings.max_preview_height,
(length_current_cmd + preview_width - 1 - border_size) (length_current_cmd + preview_width - 1 - border_size)