diff --git a/src/pager.cpp b/src/pager.cpp index 3c4adc7dd..deacdd960 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -88,10 +88,10 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s UNUSED(column); UNUSED(row); UNUSED(rendering); - int comp_width, desc_width; + size_t comp_width, desc_width; line_t line_data; - if (c->pref_width <= width) { + if (c->preferred_width() <= width) { // The entry fits, we give it as much space as it wants. comp_width = c->comp_width; desc_width = c->desc_width; @@ -293,9 +293,6 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring & // Compute desc_width. comp->desc_width = fish_wcswidth(comp->desc.c_str()); - - // Compute preferred width. - comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width ? 4 : 0); } recalc_min_widths(infos); @@ -417,7 +414,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co if (lst.size() <= col * row_count + row) continue; c = &lst.at(col * row_count + row); - pref = c->pref_width; + pref = c->preferred_width(); min = c->min_width; if (col != cols - 1) { diff --git a/src/pager.h b/src/pager.h index dccfb74e9..7ab26c489 100644 --- a/src/pager.h +++ b/src/pager.h @@ -74,8 +74,6 @@ class pager_t { size_t comp_width; /// On-screen width of the description information. size_t desc_width; - /// Preferred total width. - size_t pref_width; /// Minimum acceptable width. size_t min_width; @@ -85,8 +83,20 @@ class pager_t { representative(L""), comp_width(0), desc_width(0), - pref_width(0), min_width(0) {} + + // Returns the width of the separator between the + // completion and description. If we have no description, + // we have no separator width + size_t separator_width() const { + return this->desc_width > 0 ? 4 : 0; + } + + // Returns the preferred width, containing the sum of the + // width of the completion, separator, and description + size_t preferred_width() const { + return this->comp_width + this->desc_width + this->separator_width(); + } }; private: