feat: smart case search (#7385)
Add "smart-case" into the cycling of already existing search modes. Fixes #6018
This commit is contained in:
1 parent
46a166d6dc
commit
9554bdd04d
8 files changed
+47
-15
No files matched your search
@@ -115,6 +115,7 @@ pub enum SelectionMode {
|
||||
pub enum Pattern {
|
||||
CaseSensitiveString(String),
|
||||
CaseInSensitiveString(String),
|
||||
CaseSmartString(String),
|
||||
Regex(String),
|
||||
CurrentSelectionOrEmptyString,
|
||||
}
|
||||
@@ -122,9 +123,10 @@ pub enum Pattern {
|
||||
impl Pattern {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
Self::CaseSensitiveString(s) | Self::CaseInSensitiveString(s) | Self::Regex(s) => {
|
||||
s.is_empty()
|
||||
}
|
||||
Self::CaseSensitiveString(s)
|
||||
| Self::CaseInSensitiveString(s)
|
||||
| Self::CaseSmartString(s)
|
||||
| Self::Regex(s) => s.is_empty(),
|
||||
Self::CurrentSelectionOrEmptyString => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
{{since('20220624-141144-bd1b7c5d')}}
|
||||
|
||||
Move the CopyMode/SearchMode cycle between case-sensitive, case-insensitive
|
||||
and regular expression match types.
|
||||
Move the CopyMode/SearchMode cycle between case-sensitive, case-insensitive,
|
||||
smart-case and regular expression match types.
|
||||
|
||||
See [`Search` key assignment](../Search.md) for details about each match types.
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm'
|
||||
@@ -17,4 +19,3 @@ return {
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
{{since('20200607-144723-74889cd4')}}
|
||||
|
||||
This action will trigger the search overlay for the current tab.
|
||||
It accepts a typed pattern string as its parameter, allowing for
|
||||
`Regex`, `CaseSensitiveString` and `CaseInSensitiveString` as
|
||||
pattern matching types.
|
||||
This action will trigger the search overlay for the current tab. It accepts a
|
||||
typed pattern string as its parameter, allowing for `Regex`,
|
||||
`CaseSensitiveString`, `CaseInSensitiveString` and `CaseSmartString` as pattern
|
||||
matching types.
|
||||
|
||||
The supported [regular expression syntax is described
|
||||
here](https://docs.rs/regex/1.3.9/regex/#syntax).
|
||||
For `Regex` matching, the supported [regular expression syntax is described here](https://docs.rs/regex/1.3.9/regex/#syntax).
|
||||
|
||||
{{since('nightly')}}
|
||||
|
||||
`CaseSmartString` was added, to make the search case-_insensitive_ until the search term
|
||||
includes any uppercase character, which triggers the search to become case-_sensitive_.
|
||||
|
||||
```lua
|
||||
local act = wezterm.action
|
||||
@@ -35,6 +38,13 @@ config.keys = {
|
||||
mods = 'SHIFT|CTRL',
|
||||
action = act.Search { CaseInSensitiveString = 'hash' },
|
||||
},
|
||||
-- search for the string "hash" matching regardless of case, until the search string is edited
|
||||
-- with an uppercase and the matching becomes case sensitive.
|
||||
{
|
||||
key = 'H',
|
||||
mods = 'SHIFT|CTRL',
|
||||
action = act.Search { CaseSmartString = 'hash' },
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+3
-2
@@ -71,8 +71,9 @@ When the search overlay is active the behavior of wezterm changes:
|
||||
* `CTRL-N` and `DownArrow` will cause the selection to move to any next matching text.
|
||||
* `PageDown` will traverse to the next match one page at a time.
|
||||
* `CTRL-R` will cycle through the pattern matching mode; the initial mode is case-sensitive
|
||||
text matching, the next will match ignoring case and the last will match using the
|
||||
[regular expression syntax described here](https://docs.rs/regex/1.3.9/regex/#syntax).
|
||||
text matching, the next will match ignoring case, the next is "smart" and will be
|
||||
case-sensitive if any input is uppercase, otherwise it will match ignoring case, and the
|
||||
last will match using the [regular expression syntax described here](https://docs.rs/regex/1.3.9/regex/#syntax).
|
||||
The matching mode is indicated in the search bar.
|
||||
* `CTRL-U` will clear the *search pattern* so you can start over.
|
||||
* `CTRL-SHIFT-C` will copy the selected text to the clipboard.
|
||||
|
||||
@@ -664,6 +664,14 @@ impl Pane for LocalPane {
|
||||
// normalize the case so we match everything lowercase
|
||||
CompiledPattern::CaseInSensitiveString(s.to_lowercase())
|
||||
}
|
||||
Pattern::CaseSmartString(s) => {
|
||||
if s.chars().any(|c| c.is_uppercase()) {
|
||||
CompiledPattern::CaseSensitiveString(s)
|
||||
} else {
|
||||
// normalize the case so we match everything lowercase
|
||||
CompiledPattern::CaseInSensitiveString(s.to_lowercase())
|
||||
}
|
||||
}
|
||||
Pattern::Regex(r) => CompiledPattern::Regex(Regex::new(&r)?),
|
||||
};
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ pub struct SearchResult {
|
||||
pub enum Pattern {
|
||||
CaseSensitiveString(String),
|
||||
CaseInSensitiveString(String),
|
||||
CaseSmartString(String),
|
||||
Regex(String),
|
||||
}
|
||||
|
||||
@@ -72,6 +73,7 @@ impl std::ops::Deref for Pattern {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::CaseSmartString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
}
|
||||
@@ -82,6 +84,7 @@ impl std::ops::DerefMut for Pattern {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::CaseSmartString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
}
|
||||
@@ -91,6 +94,7 @@ impl std::ops::DerefMut for Pattern {
|
||||
pub enum PatternType {
|
||||
CaseSensitiveString,
|
||||
CaseInSensitiveString,
|
||||
CaseSmartString,
|
||||
Regex,
|
||||
}
|
||||
|
||||
@@ -99,6 +103,7 @@ impl From<&Pattern> for PatternType {
|
||||
match value {
|
||||
Pattern::CaseSensitiveString(_) => PatternType::CaseSensitiveString,
|
||||
Pattern::CaseInSensitiveString(_) => PatternType::CaseInSensitiveString,
|
||||
Pattern::CaseSmartString(_) => PatternType::CaseSmartString,
|
||||
Pattern::Regex(_) => PatternType::Regex,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,6 +645,7 @@ impl CopyRenderable {
|
||||
match self.pattern_type {
|
||||
PatternType::CaseSensitiveString => Pattern::CaseSensitiveString(pattern),
|
||||
PatternType::CaseInSensitiveString => Pattern::CaseInSensitiveString(pattern),
|
||||
PatternType::CaseSmartString => Pattern::CaseSmartString(pattern),
|
||||
PatternType::Regex => Pattern::Regex(pattern),
|
||||
}
|
||||
}
|
||||
@@ -694,7 +695,8 @@ impl CopyRenderable {
|
||||
fn cycle_match_type(&mut self) {
|
||||
let pattern_type = match &self.pattern_type {
|
||||
PatternType::CaseSensitiveString => PatternType::CaseInSensitiveString,
|
||||
PatternType::CaseInSensitiveString => PatternType::Regex,
|
||||
PatternType::CaseInSensitiveString => PatternType::CaseSmartString,
|
||||
PatternType::CaseSmartString => PatternType::Regex,
|
||||
PatternType::Regex => PatternType::CaseSensitiveString,
|
||||
};
|
||||
self.pattern_type = pattern_type;
|
||||
@@ -1433,6 +1435,7 @@ impl Pane for CopyOverlay {
|
||||
let mode = &match pattern {
|
||||
Pattern::CaseSensitiveString(_) => "case-sensitive",
|
||||
Pattern::CaseInSensitiveString(_) => "ignore-case",
|
||||
Pattern::CaseSmartString(_) => "smart-case",
|
||||
Pattern::Regex(_) => "regex",
|
||||
};
|
||||
|
||||
@@ -1534,6 +1537,7 @@ impl Pane for CopyOverlay {
|
||||
let mode = &match pattern {
|
||||
Pattern::CaseSensitiveString(_) => "case-sensitive",
|
||||
Pattern::CaseInSensitiveString(_) => "ignore-case",
|
||||
Pattern::CaseSmartString(_) => "smart-case",
|
||||
Pattern::Regex(_) => "regex",
|
||||
};
|
||||
line.overlay_text_with_attribute(
|
||||
|
||||
@@ -3603,6 +3603,7 @@ impl TermWindow {
|
||||
match pattern {
|
||||
Pattern::CaseSensitiveString(s) => MuxPattern::CaseSensitiveString(s),
|
||||
Pattern::CaseInSensitiveString(s) => MuxPattern::CaseInSensitiveString(s),
|
||||
Pattern::CaseSmartString(s) => MuxPattern::CaseSmartString(s),
|
||||
Pattern::Regex(s) => MuxPattern::Regex(s),
|
||||
Pattern::CurrentSelectionOrEmptyString => {
|
||||
let text = self.selection_text(pane);
|
||||
|
||||
Reference in new issue
Block a user