From 3954200555d72f44ac8fa607865c1bbefda5d319 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 26 Jul 2022 11:52:07 +0200 Subject: [PATCH] Centralize how we invalidate pager rendering after completions change The pager's rendering_needs_update() function detects some but not all scenarios where a rendering is stale. In particular, it does not compare the completion strings. To make this work, we manually invalidate the pager rendering whenever we update completion strings. The history pager needs the same functionality, so let's move it into the pager. No functional change. --- src/pager.cpp | 5 ++++- src/pager.h | 6 +++++- src/reader.cpp | 2 -- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pager.cpp b/src/pager.cpp index 02f121aad..a5795a1f6 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -388,6 +388,7 @@ void pager_t::set_completions(const completion_list_t &raw_completions) { // Refilter them. this->refilter_completions(); + have_unrendered_completions = true; } void pager_t::set_prefix(const wcstring &pref) { prefix = pref; } @@ -575,6 +576,7 @@ page_rendering_t pager_t::render() const { } bool pager_t::rendering_needs_update(const page_rendering_t &rendering) const { + if (have_unrendered_completions) return true; // Common case is no pager. if (this->empty() && rendering.screen_data.empty()) return false; @@ -589,9 +591,10 @@ bool pager_t::rendering_needs_update(const page_rendering_t &rendering) const { (rendering.remaining_to_disclose > 0 && this->fully_disclosed); } -void pager_t::update_rendering(page_rendering_t *rendering) const { +void pager_t::update_rendering(page_rendering_t *rendering) { if (rendering_needs_update(*rendering)) { *rendering = this->render(); + have_unrendered_completions = false; } } diff --git a/src/pager.h b/src/pager.h index a7b629d46..9b65cc031 100644 --- a/src/pager.h +++ b/src/pager.h @@ -116,6 +116,10 @@ class pager_t { // The unfiltered list. Note there's a lot of duplication here. comp_info_list_t unfiltered_completion_infos; + // This tracks if the completion list has been changed since we last rendered. If yes, + // then we definitely need to re-render. + bool have_unrendered_completions = false; + wcstring prefix; bool completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst, @@ -167,7 +171,7 @@ class pager_t { bool rendering_needs_update(const page_rendering_t &rendering) const; // Updates the rendering. - void update_rendering(page_rendering_t *rendering) const; + void update_rendering(page_rendering_t *rendering); // Indicates if there are no completions, and therefore nothing to render. bool empty() const; diff --git a/src/reader.cpp b/src/reader.cpp index 9c271deb6..46ba148ad 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2180,8 +2180,6 @@ bool reader_data_t::handle_completions(const completion_list_t &comp, size_t tok // Update the pager data. pager.set_prefix(prefix); pager.set_completions(surviving_completions); - // Invalidate our rendering. - current_page_rendering = page_rendering_t(); // Modify the command line to reflect the new pager. pager_selection_changed(); return false;