From a56d0cfd5ecdc5e47dffa88a22083fe0f04abc25 Mon Sep 17 00:00:00 2001 From: Matthew Berryman Date: Wed, 12 Mar 2025 20:53:48 +1030 Subject: [PATCH] fix: multiline command does not honour max_preview_height (#2624) Resolves #2610 --- .../src/command/client/search/interactive.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/atuin/src/command/client/search/interactive.rs b/crates/atuin/src/command/client/search/interactive.rs index 4b672705..3c63dc70 100644 --- a/crates/atuin/src/command/client/search/interactive.rs +++ b/crates/atuin/src/command/client/search/interactive.rs @@ -540,8 +540,27 @@ impl State { && !results.is_empty() { 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 - if length_current_cmd > preview_width - 19 { + else if length_current_cmd > preview_width - 19 { std::cmp::min( settings.max_preview_height, (length_current_cmd + preview_width - 1 - border_size)