diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 71157beca..1a68a3f68 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -6791,31 +6791,35 @@ fn best>( } // Print the completion list. - let mut prefix = WString::new(); - if will_replace_token { - if use_prefix { - prefix.push_utfstr(&common_prefix); - } - } else if tok.len() + common_prefix.len() <= PREFIX_MAX_LEN { - prefix.push_utfstr(&tok); - prefix.push_utfstr(&common_prefix); + let prefix = if will_replace_token && !use_prefix { + Cow::Borrowed(L!("")) } else { - // Collapse parent directories and append end of string - prefix.push(get_ellipsis_char()); - - let full = tok + common_prefix; - let truncated = &full[full.len() - PREFIX_MAX_LEN..]; - let (i, last_component) = truncated.split('/').enumerate().last().unwrap(); - if i == 0 { - // No path separators were found in the common prefix, so we can't collapse - // any further - prefix.push_utfstr(&truncated); + let mut prefix = WString::new(); + let full = if will_replace_token { + common_prefix.to_owned() } else { - // Discard any parent directories and include whats left - prefix.push('/'); - prefix.push_utfstr(last_component); + tok + common_prefix }; - } + if full.len() <= PREFIX_MAX_LEN { + prefix = full; + } else { + // Collapse parent directories and append end of string + prefix.push(get_ellipsis_char()); + + let truncated = &full[full.len() - PREFIX_MAX_LEN..]; + let (i, last_component) = truncated.split('/').enumerate().last().unwrap(); + if i == 0 { + // No path separators were found in the common prefix, so we can't collapse + // any further + prefix.push_utfstr(&truncated); + } else { + // Discard any parent directories and include whats left + prefix.push('/'); + prefix.push_utfstr(last_component); + }; + } + Cow::Owned(prefix) + }; if use_prefix { let common_prefix_len = common_prefix.len(); @@ -6831,7 +6835,7 @@ fn best>( } // Update the pager data. - self.pager.set_prefix(Cow::Owned(prefix), true); + self.pager.set_prefix(prefix, true); self.pager.set_completions(&surviving_completions, true); // Modify the command line to reflect the new pager. self.pager_selection_changed(); diff --git a/tests/checks/tmux-complete2.fish b/tests/checks/tmux-complete2.fish index 071c11c91..0e5059142 100644 --- a/tests/checks/tmux-complete2.fish +++ b/tests/checks/tmux-complete2.fish @@ -35,7 +35,7 @@ isolated-tmux send-keys 'echo $FISH_TEST_v' Tab tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 1> echo $FISH_TEST_VAR_ -# CHECK: $FISH_TEST_VAR_1 (Variable: /) $FISH_TEST_VAR_2 (Variable: /) +# CHECK: …TEST_VAR_1 (Variable: /) …TEST_VAR_2 (Variable: /) mkdir -p clang/include touch clang/INSTALL.txt @@ -51,3 +51,10 @@ tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 1> : clang/include # CHECK: clang/INSTALL.txt …/include/ …/include-2/ + +isolated-tmux send-keys C-u 'complete truncate_custom_compl -a "Foo/bar/baz/{111,222,333}"' \ + Enter C-l 'truncate_custom_compl foo' Tab +tmux-sleep +isolated-tmux capture-pane -p +# CHECK: prompt 2> truncate_custom_compl Foo/bar/baz/ +# CHECK: …/111 …/222 …/333