mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 14:31:09 +08:00
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.
This commit is contained in:
parent
2410e27d10
commit
3954200555
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user