mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
search mode can now default to searching the selection text
To do this, we split `Pattern` into the underlying pattern for the mux layer (which is part of the codec), and another for the config layer, so that we can specify this new mode. At the gui layer, we translate the selection variant into the actual selection text and map it to the mux Pattern enum. When taking the selection text, we restrict it to just the first line. refs: https://github.com/wez/wezterm/issues/1912
This commit is contained in:
parent
e8c3de9c16
commit
107d3d2378
@ -104,37 +104,28 @@ pub enum SelectionMode {
|
||||
Block,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||
pub enum Pattern {
|
||||
CaseSensitiveString(String),
|
||||
CaseInSensitiveString(String),
|
||||
Regex(String),
|
||||
CurrentSelectionOrEmptyString,
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
Self::CaseSensitiveString(s) | Self::CaseInSensitiveString(s) | Self::Regex(s) => {
|
||||
s.is_empty()
|
||||
}
|
||||
Self::CurrentSelectionOrEmptyString => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Pattern {
|
||||
fn default() -> Self {
|
||||
Self::CaseSensitiveString("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Pattern {
|
||||
type Target = String;
|
||||
fn deref(&self) -> &String {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for Pattern {
|
||||
fn deref_mut(&mut self) -> &mut String {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
Self::CurrentSelectionOrEmptyString
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* In Copy Mode, `CTRL-v` will enable rectangular block selection mode. [#1656](https://github.com/wez/wezterm/issues/1656)
|
||||
* Copy Mode: key assignments are [now configurable](copymode.md#configurable-key-assignments) [#993](https://github.com/wez/wezterm/issues/993)
|
||||
* Search Mode: key assignments are [now configurable](scrollback.md#configurable-key-assignments) [#993](https://github.com/wez/wezterm/issues/993)
|
||||
* Search Mode: the default `CTRL-SHIFT-F` key assignment now defaults to the new `CurrentSelectionOrEmptyString` mode to search for the current selection text, if any. See [Search](config/lua/keyassignment/Search.md) for more info.
|
||||
* Copy Mode and Search Mode can be toggled and remember search results and cursor positioning, making it easier to locate and select text without using the mouse [#1592](https://github.com/wez/wezterm/issues/1592)
|
||||
* In the Launcher Menu, you may now use `CTRL-G` to cancel/exit the launcher [#1977](https://github.com/wez/wezterm/issues/1977)
|
||||
* [cell_width](config/lua/config/cell_width.md) option to adjust the horizontal spacing when the availble font stretches are insufficient. [#1979](https://github.com/wez/wezterm/issues/1979)
|
||||
|
@ -27,3 +27,8 @@ return {
|
||||
|
||||
[Learn more about the search overlay](../../../scrollback.html#searching-the-scrollback)
|
||||
|
||||
*since: nightly builds only*
|
||||
|
||||
You may now use `wezterm.action{Search="CurrentSelectionOrEmptyString"}` to have the search take the currently selected text as the item to search.
|
||||
|
||||
The selection text is adjusted to be a single line.
|
||||
|
@ -41,7 +41,39 @@ pub struct SearchResult {
|
||||
pub match_id: usize,
|
||||
}
|
||||
|
||||
pub use config::keyassignment::Pattern;
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub enum Pattern {
|
||||
CaseSensitiveString(String),
|
||||
CaseInSensitiveString(String),
|
||||
Regex(String),
|
||||
}
|
||||
|
||||
impl Default for Pattern {
|
||||
fn default() -> Self {
|
||||
Self::CaseSensitiveString("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Pattern {
|
||||
type Target = String;
|
||||
fn deref(&self) -> &String {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for Pattern {
|
||||
fn deref_mut(&mut self) -> &mut String {
|
||||
match self {
|
||||
Pattern::CaseSensitiveString(s) => s,
|
||||
Pattern::CaseInSensitiveString(s) => s,
|
||||
Pattern::Regex(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a close request is being made
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
|
@ -279,7 +279,7 @@ static DEFS: &[CommandDef] = &[
|
||||
brief: "Search pane output",
|
||||
doc: "Enters the search mode UI for the current pane",
|
||||
exp: |exp| {
|
||||
exp.push(Search(Pattern::CaseSensitiveString("".into())));
|
||||
exp.push(Search(Pattern::CurrentSelectionOrEmptyString));
|
||||
},
|
||||
keys: &[(Modifiers::SUPER, "f")],
|
||||
args: &[ArgType::ActivePane],
|
||||
|
@ -30,7 +30,7 @@ use config::{
|
||||
TermConfig, WindowCloseConfirmation,
|
||||
};
|
||||
use mlua::{FromLua, UserData, UserDataFields};
|
||||
use mux::pane::{CloseReason, Pane, PaneId};
|
||||
use mux::pane::{CloseReason, Pane, PaneId, Pattern as MuxPattern};
|
||||
use mux::renderable::RenderableDimensions;
|
||||
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, Tab, TabId};
|
||||
use mux::window::WindowId as MuxWindowId;
|
||||
@ -2263,7 +2263,7 @@ impl TermWindow {
|
||||
let mut params = existing.get_params();
|
||||
params.editing_search = true;
|
||||
if !pattern.is_empty() {
|
||||
params.pattern = pattern.clone();
|
||||
params.pattern = self.resolve_search_pattern(pattern.clone(), &pane);
|
||||
}
|
||||
existing.apply_params(params);
|
||||
replace_current = true;
|
||||
@ -2272,7 +2272,7 @@ impl TermWindow {
|
||||
self,
|
||||
&pane,
|
||||
CopyModeParams {
|
||||
pattern: pattern.clone(),
|
||||
pattern: self.resolve_search_pattern(pattern.clone(), &pane),
|
||||
editing_search: true,
|
||||
},
|
||||
);
|
||||
@ -2320,7 +2320,7 @@ impl TermWindow {
|
||||
self,
|
||||
&pane,
|
||||
CopyModeParams {
|
||||
pattern: Pattern::default(),
|
||||
pattern: MuxPattern::default(),
|
||||
editing_search: false,
|
||||
},
|
||||
);
|
||||
@ -2887,6 +2887,23 @@ impl TermWindow {
|
||||
});
|
||||
self.update_title();
|
||||
}
|
||||
|
||||
fn resolve_search_pattern(&self, pattern: Pattern, pane: &Rc<dyn Pane>) -> MuxPattern {
|
||||
match pattern {
|
||||
Pattern::CaseSensitiveString(s) => MuxPattern::CaseSensitiveString(s),
|
||||
Pattern::CaseInSensitiveString(s) => MuxPattern::CaseInSensitiveString(s),
|
||||
Pattern::Regex(s) => MuxPattern::Regex(s),
|
||||
Pattern::CurrentSelectionOrEmptyString => {
|
||||
let text = self.selection_text(pane);
|
||||
let first_line = text
|
||||
.lines()
|
||||
.next()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_default();
|
||||
MuxPattern::CaseSensitiveString(first_line)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TermWindow {
|
||||
|
Loading…
Reference in New Issue
Block a user