aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-02-05 11:02:39 +0100
committerGitHub <noreply@github.com>2026-02-05 11:02:39 +0100
commita5f6ac81f477a7dbfb3c0398c562016e24c09ba9 (patch)
treecf49041da9bc7aed50d3b23952757d3ccec45820
parentAllow resizing panes with the mouse (#4678) (diff)
downloadsl0ppij-a5f6ac81f477a7dbfb3c0398c562016e24c09ba9.tar.gz
sl0ppij-a5f6ac81f477a7dbfb3c0398c562016e24c09ba9.tar.xz
sl0ppij-a5f6ac81f477a7dbfb3c0398c562016e24c09ba9.zip
fix: don't trim empty characters with background (#4680)
* fix: take background color into account when trimming characters * add pr
-rw-r--r--CHANGELOG.md1
-rw-r--r--zellij-server/src/panes/grid.rs10
-rw-r--r--zellij-server/src/panes/unit/grid_tests.rs91
-rw-r--r--zellij-utils/src/cli.rs2
4 files changed, 102 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 981accdb..bf5d3d77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* feat: allow explicitly saving current session for resurrection (rather than waiting on the resurrection interval) (https://github.com/zellij-org/zellij/pull/4654)
* fix: proper error handling in route (https://github.com/zellij-org/zellij/pull/4655)
* feat: allow resizing panes with the mouse (https://github.com/zellij-org/zellij/pull/4678)
+* fix: don't trim empty colored cells when resizing terminal grid (https://github.com/zellij-org/zellij/pull/4680)
## [0.43.1] - 2025-08-08
diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs
index 4d17972e..ee88e40c 100644
--- a/zellij-server/src/panes/grid.rs
+++ b/zellij-server/src/panes/grid.rs
@@ -861,9 +861,17 @@ impl Grid {
for line in &mut viewport_canonical_lines {
let mut trim_at = None;
for (index, character) in line.columns.iter().enumerate() {
- if character.character != EMPTY_TERMINAL_CHARACTER.character {
+ let is_trimmable_space = character.character
+ == EMPTY_TERMINAL_CHARACTER.character
+ && matches!(character.styles.background, Some(AnsiCode::Reset) | None);
+
+ if !is_trimmable_space {
+ // we can't trim this character, meaning that if we had a previous
+ // character that we marked as the trim_at point, we need to clear it
trim_at = None;
} else if trim_at.is_none() {
+ // we CAN trim this character, set the trim_at point only if it's not set
+ // because we want the trim_at point to be the EARLIEST trimmable character
trim_at = Some(index);
}
}
diff --git a/zellij-server/src/panes/unit/grid_tests.rs b/zellij-server/src/panes/unit/grid_tests.rs
index 7128bc07..c584e021 100644
--- a/zellij-server/src/panes/unit/grid_tests.rs
+++ b/zellij-server/src/panes/unit/grid_tests.rs
@@ -4128,3 +4128,94 @@ fn cannot_escape_scroll_region() {
}
assert_snapshot!(format!("{:?}", grid));
}
+
+#[test]
+fn preserve_background_color_on_resize() {
+ use crate::panes::terminal_character::{AnsiCode, EMPTY_TERMINAL_CHARACTER};
+
+ let mut vte_parser = vte::Parser::new();
+ let sixel_image_store = Rc::new(RefCell::new(SixelImageStore::default()));
+ let terminal_emulator_color_codes = Rc::new(RefCell::new(HashMap::new()));
+ let debug = false;
+ let arrow_fonts = true;
+ let styled_underlines = true;
+ let osc8_hyperlinks = true;
+ let explicitly_disable_kitty_keyboard_protocol = false;
+ let mut grid = Grid::new(
+ 10,
+ 20,
+ Rc::new(RefCell::new(Palette::default())),
+ terminal_emulator_color_codes,
+ Rc::new(RefCell::new(LinkHandler::new())),
+ Rc::new(RefCell::new(None)),
+ sixel_image_store,
+ Style::default(),
+ debug,
+ arrow_fonts,
+ styled_underlines,
+ osc8_hyperlinks,
+ explicitly_disable_kitty_keyboard_protocol,
+ );
+
+ let mut parse = |s, grid: &mut Grid| {
+ for b in Vec::from(s) {
+ vte_parser.advance(&mut *grid, b)
+ }
+ };
+
+ // Write text with red background that extends to end of line
+ // ESC[41m = red background
+ // ESC[K = clear to end of line (fills with current background)
+ // ESC[0m = reset
+ let content = "test\x1b[41m\x1b[K\x1b[0m";
+ parse(content, &mut grid);
+
+ // Check that characters after "test" have red background before resize
+ let first_row = &grid.viewport[0];
+ let background_char_count_before = first_row
+ .columns
+ .iter()
+ .enumerate()
+ .filter(|(i, c)| *i >= 4 && c.styles.background != Some(AnsiCode::Reset))
+ .count();
+ assert!(
+ background_char_count_before > 0,
+ "Should have characters with background color before resize"
+ );
+
+ // Also check that plain trailing spaces are properly trimmed (regression test)
+ let content2 = "\r\n\rplain text with spaces ";
+ parse(content2, &mut grid);
+
+ // Resize the grid
+ grid.change_size(10, 30);
+
+ // Check that the background color is preserved after resize
+ let first_row = &grid.viewport[0];
+ let background_char_count_after = first_row
+ .columns
+ .iter()
+ .enumerate()
+ .filter(|(i, c)| *i >= 4 && c.styles.background != Some(AnsiCode::Reset))
+ .count();
+ assert_eq!(
+ background_char_count_before, background_char_count_after,
+ "Background colored characters should be preserved after resize"
+ );
+
+ // Verify that the second line doesn't have excessive trailing spaces
+ // (it should be trimmed since they're plain spaces without background color)
+ let second_row = &grid.viewport[1];
+ let trailing_spaces = second_row
+ .columns
+ .iter()
+ .rev()
+ .take_while(|c| c.character == EMPTY_TERMINAL_CHARACTER.character)
+ .count();
+ // All trailing plain spaces should be completely removed
+ assert_eq!(
+ trailing_spaces, 0,
+ "Plain trailing spaces should be completely trimmed, but found {} trailing spaces",
+ trailing_spaces
+ );
+}
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 5f4d17d0..610e9085 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -765,7 +765,7 @@ pub enum CliAction {
near_current_pane: bool,
/// start this pane without a border (warning: will make it impossible to move with the
/// mouse)
- #[clap(short, long, value_parser)]
+ #[clap(long, value_parser)]
borderless: Option<bool>,
},
/// Open the specified file in a new zellij pane with your default EDITOR