Skip to content

Commit

Permalink
Format + fix to prepare for PR to resolve #4226.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kongsgaard authored and Daniel Kongsgaard committed Aug 31, 2023
1 parent 5974746 commit 1da48d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
2 changes: 0 additions & 2 deletions config/src/keyassignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ pub struct InputSelector {
#[dynamic(default)]
pub fuzzy: bool,

// Overrides the main input_select_alphabet config
#[dynamic(default = "default_num_alphabet")]
pub alphabet: String,

Expand All @@ -494,7 +493,6 @@ fn default_description() -> String {
"Select an item and press Enter = accept, Esc = cancel, / = filter".to_string()
}


#[derive(Debug, Clone, PartialEq, FromDynamic, ToDynamic)]
pub enum KeyAssignment {
SpawnTab(SpawnTabDomain),
Expand Down
2 changes: 1 addition & 1 deletion docs/config/lua/keyassignment/InputSelector.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ config.keys = {
title = 'I am title',
choices = choices,
alphabet = '123456789',
description = 'Write the number you want to choose.',
description = 'Write the number you want to choose or press / to search.',
},
pane
)
Expand Down
32 changes: 10 additions & 22 deletions wezterm-gui/src/overlay/selector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::quickselect::compute_labels_for_alphabet;
use crate::scripting::guiwin::GuiWin;
use config::keyassignment::{InputSelector, InputSelectorEntry, KeyAssignment};
use fuzzy_matcher::skim::SkimMatcherV2;
Expand All @@ -11,7 +12,6 @@ use termwiz::input::{InputEvent, KeyCode, KeyEvent, Modifiers, MouseButtons, Mou
use termwiz::surface::{Change, Position};
use termwiz::terminal::Terminal;
use termwiz_funcs::truncate_right;
use super::quickselect::compute_labels_for_alphabet;

const ROW_OVERHEAD: usize = 3;

Expand Down Expand Up @@ -79,26 +79,15 @@ impl SelectorState {
x: Position::Absolute(0),
y: Position::Absolute(0),
},
Change::Text(format!(
"{}\r\n",
truncate_right(
desc,
max_width
)
)),
Change::Text(format!("{}\r\n", truncate_right(desc, max_width))),
Change::AllAttributes(CellAttributes::default()),
];

let max_items = self.max_items;
let alphabet = &self.args.alphabet;
let mut labels = compute_labels_for_alphabet(alphabet, max_items+1)
.into_iter();
let mut labels = compute_labels_for_alphabet(alphabet, max_items + 1).into_iter();
let labels_len = labels.len();
let max_label_len = labels
.clone()
.map(|s| s.len())
.max()
.unwrap_or(0);
let max_label_len = labels.clone().map(|s| s.len()).max().unwrap_or(0);

for (row_num, (entry_idx, entry)) in self
.filtered_entries
Expand All @@ -123,15 +112,14 @@ impl SelectorState {
// and we are not filtering
if !self.filtering && row_num < labels_len {
if let Some(s) = labels.next() {
let ex_spaces = " ".to_string()
.repeat(max_label_len - s.len() + 1);
let ex_spaces = " ".to_string().repeat(max_label_len - s.len() + 1);
changes.push(Change::Text(format!("{}{}. ", ex_spaces, s)));
}
} else if !self.filtering {
changes.push(Change::Text(format!("{}",
" ".to_string()
.repeat(max_label_len+3)
)));
changes.push(Change::Text(format!(
"{}",
" ".to_string().repeat(max_label_len + 3)
)));
} else {
changes.push(Change::Text(" ".to_string()));
}
Expand Down Expand Up @@ -205,7 +193,7 @@ impl SelectorState {
let alphabet = self.args.alphabet.to_lowercase();
let alphabet_has_j = alphabet.contains("j");
let alphabet_has_k = alphabet.contains("k");
let labels = compute_labels_for_alphabet(&alphabet, max_items+1);
let labels = compute_labels_for_alphabet(&alphabet, max_items + 1);

while let Ok(Some(event)) = term.poll_input(None) {
match event {
Expand Down

0 comments on commit 1da48d1

Please sign in to comment.