Skip to content

Commit 5826d06

Browse files
committed
tmp
1 parent 221ab21 commit 5826d06

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/completion/base.rs

+7
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ pub struct Suggestion {
9393
/// This helps to avoid that a completer repeats the complete suggestion.
9494
pub append_whitespace: bool,
9595
}
96+
97+
impl Suggestion {
98+
/// Returns display if set, otherwise value.
99+
pub fn display_or_value(&self) -> &String {
100+
self.display.as_ref().unwrap_or(&self.value)
101+
}
102+
}

src/menu/columnar_menu.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl ColumnarMenu {
351351
.reverse()
352352
.prefix(),
353353
self.color.selected_text_style.prefix(),
354-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
354+
suggestion.display_or_value(),
355355
RESET,
356356
self.color.description_style.reverse().prefix(),
357357
self.color.selected_text_style.prefix(),
@@ -373,7 +373,7 @@ impl ColumnarMenu {
373373
.reverse()
374374
.prefix(),
375375
self.color.selected_text_style.prefix(),
376-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
376+
suggestion.display_or_value(),
377377
RESET,
378378
"",
379379
self.end_of_line(column),
@@ -386,7 +386,7 @@ impl ColumnarMenu {
386386
format!(
387387
"{}{:max$}{}{}{}{}{}",
388388
suggestion.style.unwrap_or(self.color.text_style).prefix(),
389-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
389+
suggestion.display_or_value(),
390390
RESET,
391391
self.color.description_style.prefix(),
392392
description
@@ -402,7 +402,7 @@ impl ColumnarMenu {
402402
format!(
403403
"{}{}{}{}{:>empty$}{}{}",
404404
suggestion.style.unwrap_or(self.color.text_style).prefix(),
405-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
405+
suggestion.display_or_value(),
406406
RESET,
407407
self.color.description_style.prefix(),
408408
"",
@@ -419,7 +419,7 @@ impl ColumnarMenu {
419419
format!(
420420
"{}{:max$}{}{}",
421421
marker,
422-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
422+
suggestion.display_or_value(),
423423
description
424424
.chars()
425425
.take(empty_space)
@@ -436,7 +436,7 @@ impl ColumnarMenu {
436436
format!(
437437
"{}{}{:>empty$}{}",
438438
marker,
439-
suggestion.display.as_ref().unwrap_or(&suggestion.value),
439+
suggestion.display_or_value(),
440440
"",
441441
self.end_of_line(column),
442442
empty = empty_space.saturating_sub(marker.len()),
@@ -590,11 +590,7 @@ impl Menu for ColumnarMenu {
590590
self.working_details.col_width = painter.screen_width() as usize;
591591

592592
self.longest_suggestion = self.get_values().iter().fold(0, |prev, suggestion| {
593-
let suggestion_length = suggestion
594-
.display
595-
.as_ref()
596-
.unwrap_or(&suggestion.value)
597-
.len();
593+
let suggestion_length = suggestion.display_or_value().len();
598594
if prev >= suggestion_length {
599595
prev
600596
} else {
@@ -603,7 +599,8 @@ impl Menu for ColumnarMenu {
603599
});
604600
} else {
605601
let max_width = self.get_values().iter().fold(0, |acc, suggestion| {
606-
let str_len = suggestion.value.len() + self.default_details.col_padding;
602+
let str_len =
603+
suggestion.display_or_value().len() + self.default_details.col_padding;
607604
if str_len > acc {
608605
str_len
609606
} else {
@@ -739,7 +736,9 @@ impl Menu for ColumnarMenu {
739736
// Correcting the enumerate index based on the number of skipped values
740737
let index = index + skip_values;
741738
let column = index as u16 % self.get_cols();
742-
let empty_space = self.get_width().saturating_sub(suggestion.value.len());
739+
let empty_space = self
740+
.get_width()
741+
.saturating_sub(suggestion.display_or_value().len());
743742

744743
self.create_string(suggestion, index, column, empty_space, use_ansi_coloring)
745744
})

0 commit comments

Comments
 (0)