diff --git a/src/builtins/complete.rs b/src/builtins/complete.rs index 4014ec208..e744570f4 100644 --- a/src/builtins/complete.rs +++ b/src/builtins/complete.rs @@ -517,7 +517,8 @@ pub fn complete(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> next.flags, faux_cmdline, &mut tmp_cursor, - false, + /*append_only=*/ false, + /*is_unique=*/ false, ); // completion_apply_to_command_line will append a space unless COMPLETE_NO_SPACE diff --git a/src/reader.rs b/src/reader.rs index b8149c3b7..e3294f5f3 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3777,6 +3777,7 @@ fn pager_selection_changed(&mut self) { &self.cycle_command_line, &mut cursor_pos, false, + /*is_unique=*/ false, // don't care ), }; @@ -4414,6 +4415,7 @@ fn get_autosuggestion_performer( &search_string, &mut cursor, /*append_only=*/ true, + /*is_unique=*/ false, ); } result @@ -5597,6 +5599,7 @@ pub fn completion_apply_to_command_line( command_line: &wstr, inout_cursor_pos: &mut usize, append_only: bool, + is_unique: bool, ) -> WString { let add_space = !flags.contains(CompleteFlags::NO_SPACE); let do_replace_token = flags.contains(CompleteFlags::REPLACES_TOKEN); @@ -5621,7 +5624,7 @@ pub fn completion_apply_to_command_line( } let mut escape_flags = EscapeFlags::empty(); - if append_only || !add_space { + if append_only || !is_unique || !add_space { escape_flags.insert(EscapeFlags::NO_QUOTED); } if no_tilde { @@ -5869,7 +5872,12 @@ fn try_insert(&mut self, c: Completion, tok: &wstr, token_range: Range) { // If this is a replacement completion, check that we know how to replace it, e.g. that // the token doesn't contain evil operators like {}. if !c.flags.contains(CompleteFlags::REPLACES_TOKEN) || reader_can_replace(tok, c.flags) { - self.completion_insert(&c.completion, token_range.end, c.flags); + self.completion_insert( + &c.completion, + token_range.end, + c.flags, + /*is_unique=*/ true, + ); } } @@ -6005,7 +6013,12 @@ fn handle_completions(&mut self, token_range: Range) -> bool { if prefix_is_partial_completion { flags |= CompleteFlags::NO_SPACE; } - self.completion_insert(&common_prefix, token_range.end, flags); + self.completion_insert( + &common_prefix, + token_range.end, + flags, + /*is_unique=*/ false, + ); self.cycle_command_line = self.command_line.text().to_owned(); self.cycle_cursor_pos = self.command_line.position(); } @@ -6049,7 +6062,13 @@ fn handle_completions(&mut self, token_range: Range) -> bool { /// \param token_end the position after the token to complete /// \param flags A union of all flags describing the completion to insert. See the completion_t /// struct for more information on possible values. - fn completion_insert(&mut self, val: &wstr, token_end: usize, flags: CompleteFlags) { + fn completion_insert( + &mut self, + val: &wstr, + token_end: usize, + flags: CompleteFlags, + is_unique: bool, + ) { let (elt, el) = self.active_edit_line(); // Move the cursor to the end of the token. @@ -6065,6 +6084,7 @@ fn completion_insert(&mut self, val: &wstr, token_end: usize, flags: CompleteFla el.text(), &mut cursor, /*append_only=*/ false, + is_unique, ); self.set_buffer_maintaining_pager(&new_command_line, cursor, false); } diff --git a/src/tests/complete.rs b/src/tests/complete.rs index 21f267e30..cd6312228 100644 --- a/src/tests/complete.rs +++ b/src/tests/complete.rs @@ -160,7 +160,8 @@ macro_rules! unique_completion_applies_as { completions[0].flags, cmdline, &mut cursor, - false, + /*append_only=*/ false, + /*is_unique=*/ true, ); assert_eq!(newcmdline, L!($applied), "apply result mismatch"); }; @@ -224,6 +225,7 @@ macro_rules! unique_completion_applies_as { L!("mv debug debug"), &mut cursor_pos, true, + /*is_unique=*/ false, ); assert_eq!(newcmdline, L!("mv debug Debug/")); diff --git a/src/tests/reader.rs b/src/tests/reader.rs index 2b0450a91..be5b4ec9c 100644 --- a/src/tests/reader.rs +++ b/src/tests/reader.rs @@ -57,6 +57,7 @@ macro_rules! validate { &line, &mut cursor_pos, $append_only, + /*is_unique=*/ false, ); assert_eq!(result, expected); assert_eq!(cursor_pos, out_cursor_pos); diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 1db09fd59..9ea39f260 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -10,7 +10,7 @@ complete -c complete_test_alpha3 --no-files -w 'complete_test_alpha2 extra2' complete -C'complete_test_alpha1 arg1 ' # CHECK: complete_test_alpha1 arg1 complete --escape -C'complete_test_alpha1 arg1 ' -# CHECK: 'complete_test_alpha1 arg1 ' +# CHECK: complete_test_alpha1\ arg1\{{ }} complete -C'complete_test_alpha2 arg2 ' # CHECK: complete_test_alpha1 extra1 arg2 complete -C'complete_test_alpha3 arg3 '