Skip to content

Commit

Permalink
Updated arcording to feedback (added tests).
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kongsgaard authored and Daniel Kongsgaard committed Sep 21, 2023
1 parent 90d0279 commit 18ae512
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
6 changes: 2 additions & 4 deletions docs/config/lua/keyassignment/InputSelector.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ local wezterm = require 'wezterm'
local act = wezterm.action
local config = wezterm.config_builder()

config.leader = { key = 'Space', mods = 'CTRL', timeout_milliseconds = 3000 }

config.keys = {
{
key = 'w',
mods = 'LEADER',
key = 'S',
mods = 'CTRL|SHIFT',
action = wezterm.action_callback(function(window, pane)
-- Here you can dynamically construct a longer list if needed

Expand Down
47 changes: 32 additions & 15 deletions wezterm-gui/src/overlay/quickselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,15 @@ const PATTERNS: [&str; 14] = [
/// This function computes a set of labels for a given alphabet.
/// It is derived from https://github.com/fcsonline/tmux-thumbs/blob/master/src/alphabets.rs
/// which is Copyright (c) 2019 Ferran Basora and provided under the MIT license
pub fn compute_labels_for_alphabet(
alphabet: &str,
num_matches: usize,
) -> Vec<String> {
compute_labels_for_alphabet_impl(alphabet, num_matches, true)
pub fn compute_labels_for_alphabet(alphabet: &str, num_matches: usize) -> Vec<String> {
compute_labels_for_alphabet_impl(alphabet, num_matches, true)
}

pub fn compute_labels_for_alphabet_with_preserved_case(
alphabet: &str,
num_matches: usize,
) -> Vec<String> {
compute_labels_for_alphabet_impl(alphabet, num_matches, false)
compute_labels_for_alphabet_impl(alphabet, num_matches, false)
}

fn compute_labels_for_alphabet_impl(
Expand Down Expand Up @@ -133,32 +130,29 @@ mod alphabet_test {

#[test]
fn simple_alphabet() {
assert_eq!(
compute_labels_for_alphabet("abcd", 3, true),
vec!["a", "b", "c"]
);
assert_eq!(compute_labels_for_alphabet("abcd", 3), vec!["a", "b", "c"]);
}

#[test]
fn more_matches_than_alphabet_can_represent() {
assert_eq!(
compute_labels_for_alphabet("asdfqwerzxcvjklmiuopghtybn", 792, true).len(),
compute_labels_for_alphabet("asdfqwerzxcvjklmiuopghtybn", 792).len(),
676
);
}

#[test]
fn composed_single() {
assert_eq!(
compute_labels_for_alphabet("abcd", 6, true),
compute_labels_for_alphabet("abcd", 6),
vec!["a", "b", "c", "da", "db", "dc"]
);
}

#[test]
fn composed_multiple() {
assert_eq!(
compute_labels_for_alphabet("abcd", 8, true),
compute_labels_for_alphabet("abcd", 8),
vec!["a", "b", "ca", "cb", "da", "db", "dc", "dd"]
);
}
Expand All @@ -168,10 +162,34 @@ mod alphabet_test {
// The number of chars in the alphabet limits the potential matches to fewer
// than the number of matches that we requested
assert_eq!(
compute_labels_for_alphabet("ab", 5, true),
compute_labels_for_alphabet("ab", 5),
vec!["aa", "ab", "ba", "bb"]
);
}

#[test]
fn composed_capital() {
assert_eq!(
compute_labels_for_alphabet_with_preserved_case("AB", 4),
vec!["AA", "AB", "BA", "BB"]
);
}

#[test]
fn composed_mixed() {
assert_eq!(
compute_labels_for_alphabet_with_preserved_case("aA", 4),
vec!["aa", "aA", "Aa", "AA"]
);
}

#[test]
fn lowercase_alphabet_equal() {
assert_eq!(
compute_labels_for_alphabet_with_preserved_case("abc123", 12),
compute_labels_for_alphabet("abc123", 12)
);
}
}

pub struct QuickSelectOverlay {
Expand Down Expand Up @@ -745,7 +763,6 @@ impl QuickSelectRenderable {
&self.config.quick_select_alphabet
},
uniq_results.len(),
true,
);
self.by_label.clear();

Expand Down

0 comments on commit 18ae512

Please sign in to comment.