From 195a9cfd8885d631633b414495a1f2540faa2601 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 22 Jan 2026 08:55:01 +0000 Subject: [PATCH] When history-limit is changed, apply to existing panes, not just new ones. GitHub issue 4705. --- grid-view.c | 4 ++-- grid.c | 7 +++++-- options.c | 4 ++++ session.c | 26 ++++++++++++++++++++++++++ tmux.1 | 4 +--- tmux.h | 3 ++- window-copy.c | 5 +++++ 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/grid-view.c b/grid-view.c index 7590ea42..655ec9e4 100644 --- a/grid-view.c +++ b/grid-view.c @@ -82,7 +82,7 @@ grid_view_clear_history(struct grid *gd, u_int bg) /* Scroll the lines into the history. */ for (yy = 0; yy < last; yy++) { - grid_collect_history(gd); + grid_collect_history(gd, 0); grid_scroll_history(gd, bg); } if (last < gd->sy) @@ -107,7 +107,7 @@ grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower, u_int bg) { if (gd->flags & GRID_HISTORY) { - grid_collect_history(gd); + grid_collect_history(gd, 0); if (rupper == 0 && rlower == gd->sy - 1) grid_scroll_history(gd, bg); else { diff --git a/grid.c b/grid.c index 7ad6770b..92a9ce76 100644 --- a/grid.c +++ b/grid.c @@ -375,14 +375,17 @@ grid_trim_history(struct grid *gd, u_int ny) * and shift up. */ void -grid_collect_history(struct grid *gd) +grid_collect_history(struct grid *gd, int all) { u_int ny; if (gd->hsize == 0 || gd->hsize < gd->hlimit) return; - ny = gd->hlimit / 10; + if (all) + ny = gd->hsize - gd->hlimit; + else + ny = gd->hlimit / 10; if (ny < 1) ny = 1; if (ny > gd->hsize) diff --git a/options.c b/options.c index 37160b7a..a847ad9c 100644 --- a/options.c +++ b/options.c @@ -1252,6 +1252,10 @@ options_push_changes(const char *name) utf8_update_width_cache(); if (strcmp(name, "input-buffer-size") == 0) input_set_buffer_size(options_get_number(global_options, name)); + if (strcmp(name, "history-limit") == 0) { + RB_FOREACH(s, sessions, &sessions) + session_update_history(s); + } RB_FOREACH(s, sessions, &sessions) status_update_cache(s); diff --git a/session.c b/session.c index 51430678..afa48637 100644 --- a/session.c +++ b/session.c @@ -768,3 +768,29 @@ session_theme_changed(struct session *s) } } } + +/* Update history for all panes. */ +void +session_update_history(struct session *s) +{ + struct winlink *wl; + struct window_pane *wp; + struct grid *gd; + u_int limit, osize; + + limit = options_get_number(s->options, "history-limit"); + RB_FOREACH(wl, winlinks, &s->windows) { + TAILQ_FOREACH(wp, &wl->window->panes, entry) { + gd = wp->base.grid; + + osize = gd->hsize; + gd->hlimit = limit; + grid_collect_history(gd, 1); + + if (gd->hsize != osize) { + log_debug("%s: %%%u %u -> %u", __func__, wp->id, + osize, gd->hsize); + } + } + } +} diff --git a/tmux.1 b/tmux.1 index bf051794..f58511f2 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4583,9 +4583,7 @@ If set to 0, messages and indicators are displayed until a key is pressed. .Ar time is in milliseconds. .It Ic history-limit Ar lines -Set the maximum number of lines held in window history. -This setting applies only to new windows - existing window histories are not -resized and retain the limit at the point they were created. +Set the maximum number of lines held in pane history. .It Ic initial-repeat-time Ar time Set the time in milliseconds for the initial repeat when a key is bound with the .Fl r diff --git a/tmux.h b/tmux.h index e5145b10..74447785 100644 --- a/tmux.h +++ b/tmux.h @@ -3002,7 +3002,7 @@ int grid_cells_look_equal(const struct grid_cell *, struct grid *grid_create(u_int, u_int, u_int); void grid_destroy(struct grid *); int grid_compare(struct grid *, struct grid *); -void grid_collect_history(struct grid *); +void grid_collect_history(struct grid *, int); void grid_remove_history(struct grid *, u_int ); void grid_scroll_history(struct grid *, u_int); void grid_scroll_history_region(struct grid *, u_int, u_int, u_int); @@ -3485,6 +3485,7 @@ u_int session_group_count(struct session_group *); u_int session_group_attached_count(struct session_group *); void session_renumber_windows(struct session *); void session_theme_changed(struct session *); +void session_update_history(struct session *); /* utf8.c */ enum utf8_state utf8_towc (const struct utf8_data *, wchar_t *); diff --git a/window-copy.c b/window-copy.c index 82c0f47f..04cfe85d 100644 --- a/window-copy.c +++ b/window-copy.c @@ -2708,6 +2708,11 @@ window_copy_cmd_refresh_from_pane(struct window_copy_cmd_state *cs) data->backing = window_copy_clone_screen(&wp->base, &data->screen, NULL, NULL, wme->swp != wme->wp); + if (data->oy > screen_hsize(data->backing)) { + data->cy = 0; + data->oy = screen_hsize(data->backing); + } + window_copy_size_changed(wme); return (WINDOW_COPY_CMD_REDRAW); }