mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 03:35:17 +00:00
Extract function for potentially case-insensitive prefix check
This commit is contained in:
parent
a4f4ae76cb
commit
7049352e61
2 changed files with 25 additions and 8 deletions
|
@ -131,9 +131,9 @@ use crate::tokenizer::{
|
||||||
TOK_SHOW_COMMENTS,
|
TOK_SHOW_COMMENTS,
|
||||||
};
|
};
|
||||||
use crate::wchar::prelude::*;
|
use crate::wchar::prelude::*;
|
||||||
|
use crate::wcstringutil::string_prefixes_string_maybe_case_insensitive;
|
||||||
use crate::wcstringutil::{
|
use crate::wcstringutil::{
|
||||||
count_preceding_backslashes, join_strings, string_prefixes_string,
|
count_preceding_backslashes, join_strings, string_prefixes_string, StringFuzzyMatch,
|
||||||
string_prefixes_string_case_insensitive, StringFuzzyMatch,
|
|
||||||
};
|
};
|
||||||
use crate::wildcard::wildcard_has;
|
use crate::wildcard::wildcard_has;
|
||||||
use crate::wutil::{fstat, perror};
|
use crate::wutil::{fstat, perror};
|
||||||
|
@ -4496,7 +4496,11 @@ impl<'a> Reader<'a> {
|
||||||
self.update_autosuggestion();
|
self.update_autosuggestion();
|
||||||
} else if !result.is_empty()
|
} else if !result.is_empty()
|
||||||
&& self.can_autosuggest()
|
&& self.can_autosuggest()
|
||||||
&& string_prefixes_string_case_insensitive(&result.search_string, &result.text)
|
&& string_prefixes_string_maybe_case_insensitive(
|
||||||
|
result.icase,
|
||||||
|
&result.search_string,
|
||||||
|
&result.text,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Autosuggestion is active and the search term has not changed, so we're good to go.
|
// Autosuggestion is active and the search term has not changed, so we're good to go.
|
||||||
self.autosuggestion = result.autosuggestion;
|
self.autosuggestion = result.autosuggestion;
|
||||||
|
@ -4520,12 +4524,13 @@ impl<'a> Reader<'a> {
|
||||||
// This is also the main mechanism by which readline commands that don't change the command line
|
// This is also the main mechanism by which readline commands that don't change the command line
|
||||||
// text avoid recomputing the autosuggestion.
|
// text avoid recomputing the autosuggestion.
|
||||||
let el = &self.data.command_line;
|
let el = &self.data.command_line;
|
||||||
|
let autosuggestion = &self.autosuggestion;
|
||||||
if self.autosuggestion.text.len() > el.text().len()
|
if self.autosuggestion.text.len() > el.text().len()
|
||||||
&& if self.autosuggestion.icase {
|
&& string_prefixes_string_maybe_case_insensitive(
|
||||||
string_prefixes_string_case_insensitive(el.text(), &self.autosuggestion.text)
|
autosuggestion.icase,
|
||||||
} else {
|
&el.text(),
|
||||||
string_prefixes_string(el.text(), &self.autosuggestion.text)
|
&autosuggestion.text,
|
||||||
}
|
)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,18 @@ pub fn string_prefixes_string_case_insensitive(proposed_prefix: &wstr, value: &w
|
||||||
prefix_size <= value.len() && wcscasecmp(&value[..prefix_size], proposed_prefix).is_eq()
|
prefix_size <= value.len() && wcscasecmp(&value[..prefix_size], proposed_prefix).is_eq()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn string_prefixes_string_maybe_case_insensitive(
|
||||||
|
icase: bool,
|
||||||
|
proposed_prefix: &wstr,
|
||||||
|
value: &wstr,
|
||||||
|
) -> bool {
|
||||||
|
(if icase {
|
||||||
|
string_prefixes_string_case_insensitive
|
||||||
|
} else {
|
||||||
|
string_prefixes_string
|
||||||
|
})(proposed_prefix, value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Test if a string is a suffix of another.
|
/// Test if a string is a suffix of another.
|
||||||
pub fn string_suffixes_string_case_insensitive(proposed_suffix: &wstr, value: &wstr) -> bool {
|
pub fn string_suffixes_string_case_insensitive(proposed_suffix: &wstr, value: &wstr) -> bool {
|
||||||
let suffix_size = proposed_suffix.len();
|
let suffix_size = proposed_suffix.len();
|
||||||
|
|
Loading…
Reference in a new issue