Skip to content

Commit 8983206

Browse files
committed
♻️ ref: make selected lines take 100% width
1 parent 9523a41 commit 8983206

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/popups/conventional_commit.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,10 @@ impl ConventionalCommitPopup {
404404
}
405405

406406
#[inline]
407-
fn draw_matches_list(&self, f: &mut Frame, mut area: Rect) {
408-
// Block has two lines up and down which need to be considered
409-
const HEIGHT_BLOCK_MARGIN: usize = 2;
410-
407+
fn draw_matches_list(&self, f: &mut Frame, area: Rect) {
411408
let height = usize::from(area.height);
412409
let width = usize::from(area.width);
413410

414-
let list_height = height.saturating_sub(HEIGHT_BLOCK_MARGIN);
415-
416-
let scroll_skip =
417-
self.selected_index.saturating_sub(list_height);
418411
let quick_shortcuts = self.quick_shortcuts();
419412

420413
let title = format!(
@@ -426,19 +419,19 @@ impl ConventionalCommitPopup {
426419
}
427420
);
428421

429-
let iter_over = if let Some(commit_type) =
430-
&self.seleted_commit_type
431-
{
422+
let iter_over = if self.seleted_commit_type.is_some() {
432423
self.query_results_more_info
433424
.iter()
434425
.enumerate()
435426
.take(height)
436427
.map(|(idx, more_info)| {
437428
let (emoji, _, long_name) = more_info.strings();
438429
let text_string = format!("{emoji} {long_name}");
439-
let text =
440-
trim_length_left(&text_string, width - 4);
441-
(self.selected_index == idx, text.to_owned())
430+
let text = trim_length_left(&text_string, width);
431+
(
432+
self.selected_index == idx,
433+
format!("{text}{:width$}", " "),
434+
)
442435
})
443436
.collect_vec()
444437
} else {
@@ -453,20 +446,17 @@ impl ConventionalCommitPopup {
453446
.enumerate()
454447
.take(height)
455448
.map(|(idx, commit_type)| {
456-
let commit_type_string = commit_type.to_string();
457-
let text = trim_length_left(
458-
commit_type_string.as_str(),
459-
width - 4, // ` [k]`
449+
let text_string = format!(
450+
"{:w$} [{}]",
451+
commit_type,
452+
quick_shortcuts[idx],
453+
w = max_len.unwrap_or_default(),
460454
);
455+
let text = trim_length_left(&text_string, width);
461456

462457
(
463458
self.selected_index == idx,
464-
format!(
465-
"{:w$} [{}]",
466-
text,
467-
quick_shortcuts[idx],
468-
w = max_len.unwrap_or_default(),
469-
),
459+
format!("{text}{:width$}", " "),
470460
)
471461
})
472462
.collect_vec()
@@ -580,6 +570,15 @@ impl ConventionalCommitPopup {
580570
})
581571
.cloned()
582572
.collect_vec();
573+
574+
if self.selected_index
575+
>= self.query_results_more_info.len()
576+
{
577+
self.selected_index = self
578+
.query_results_more_info
579+
.len()
580+
.saturating_sub(1);
581+
}
583582
} else {
584583
self.query_results_type = self
585584
.options
@@ -589,6 +588,11 @@ impl ConventionalCommitPopup {
589588
})
590589
.cloned()
591590
.collect_vec();
591+
592+
if self.selected_index >= self.query_results_type.len() {
593+
self.selected_index =
594+
self.query_results_type.len().saturating_sub(1);
595+
}
592596
}
593597
}
594598

0 commit comments

Comments
 (0)