Iron out some edge-cases
This commit is contained in:
parent
2d9db0fed1
commit
a25fcfdfa7
5 changed files with 24 additions and 21 deletions
|
@ -158,6 +158,7 @@ core-graphics = { git = "https://github.com/servo/core-foundation-rs", rev = "07
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
split-debuginfo = "unpacked"
|
split-debuginfo = "unpacked"
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = true
|
debug = true
|
||||||
|
|
|
@ -702,6 +702,9 @@ impl BufferSearchBar {
|
||||||
.searchable_items_with_matches
|
.searchable_items_with_matches
|
||||||
.get(&searchable_item.downgrade())
|
.get(&searchable_item.downgrade())
|
||||||
{
|
{
|
||||||
|
if matches.len() == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let new_match_index = matches.len() - 1;
|
let new_match_index = matches.len() - 1;
|
||||||
searchable_item.update_matches(matches, cx);
|
searchable_item.update_matches(matches, cx);
|
||||||
searchable_item.activate_match(new_match_index, matches, cx);
|
searchable_item.activate_match(new_match_index, matches, cx);
|
||||||
|
|
|
@ -355,6 +355,9 @@ mod test {
|
||||||
dd
|
dd
|
||||||
ˇcc"})
|
ˇcc"})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
cx.simulate_shared_keystrokes([":", "%", "s", "/", "/", "/", "enter"])
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use gpui::{actions, impl_actions, AppContext, ViewContext};
|
use gpui::{actions, impl_actions, AppContext, ViewContext};
|
||||||
use search::{buffer_search, BufferSearchBar, SearchMode, SearchOptions};
|
use search::{buffer_search, BufferSearchBar, SearchMode, SearchOptions};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use workspace::{searchable::Direction, Pane, Toast, Workspace};
|
use workspace::{searchable::Direction, Pane, Workspace};
|
||||||
|
|
||||||
use crate::{motion::Motion, normal::move_cursor, state::SearchState, Vim};
|
use crate::{motion::Motion, normal::move_cursor, state::SearchState, Vim};
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ pub struct ReplaceCommand {
|
||||||
pub query: String,
|
pub query: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct Replacement {
|
struct Replacement {
|
||||||
search: String,
|
search: String,
|
||||||
replacement: String,
|
replacement: String,
|
||||||
|
@ -212,15 +212,7 @@ fn replace_command(
|
||||||
action: &ReplaceCommand,
|
action: &ReplaceCommand,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
let replacement = match parse_replace_all(&action.query) {
|
let replacement = parse_replace_all(&action.query);
|
||||||
Ok(replacement) => replacement,
|
|
||||||
Err(message) => {
|
|
||||||
cx.handle().update(cx, |workspace, cx| {
|
|
||||||
workspace.show_toast(Toast::new(1544, message), cx)
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let pane = workspace.active_pane().clone();
|
let pane = workspace.active_pane().clone();
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
||||||
|
@ -270,18 +262,15 @@ fn replace_command(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_replace_all(query: &str) -> Result<Replacement, String> {
|
fn parse_replace_all(query: &str) -> Replacement {
|
||||||
let mut chars = query.chars();
|
let mut chars = query.chars();
|
||||||
if Some('%') != chars.next() || Some('s') != chars.next() {
|
if Some('%') != chars.next() || Some('s') != chars.next() {
|
||||||
return Err("unsupported pattern".to_string());
|
return Replacement::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(delimeter) = chars.next() else {
|
let Some(delimeter) = chars.next() else {
|
||||||
return Err("unsupported pattern".to_string());
|
return Replacement::default();
|
||||||
};
|
};
|
||||||
if delimeter == '\\' || !delimeter.is_ascii_punctuation() {
|
|
||||||
return Err(format!("cannot use {:?} as a search delimeter", delimeter));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut search = String::new();
|
let mut search = String::new();
|
||||||
let mut replacement = String::new();
|
let mut replacement = String::new();
|
||||||
|
@ -315,7 +304,7 @@ fn parse_replace_all(query: &str) -> Result<Replacement, String> {
|
||||||
buffer = &mut flags;
|
buffer = &mut flags;
|
||||||
phase = 2;
|
phase = 2;
|
||||||
} else {
|
} else {
|
||||||
return Err("trailing characters".to_string());
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer.push(c)
|
buffer.push(c)
|
||||||
|
@ -331,14 +320,14 @@ fn parse_replace_all(query: &str) -> Result<Replacement, String> {
|
||||||
|
|
||||||
for c in flags.chars() {
|
for c in flags.chars() {
|
||||||
match c {
|
match c {
|
||||||
'g' | 'I' => {} // defaults,
|
'g' | 'I' => {}
|
||||||
'c' | 'n' => replacement.should_replace_all = false,
|
'c' | 'n' => replacement.should_replace_all = false,
|
||||||
'i' => replacement.is_case_sensitive = false,
|
'i' => replacement.is_case_sensitive = false,
|
||||||
_ => return Err(format!("unsupported flag {:?}", c)),
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(replacement)
|
replacement
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -20,3 +20,10 @@
|
||||||
{"Key":"0"}
|
{"Key":"0"}
|
||||||
{"Key":"enter"}
|
{"Key":"enter"}
|
||||||
{"Get":{"state":"aa\ndd\nˇcc","mode":"Normal"}}
|
{"Get":{"state":"aa\ndd\nˇcc","mode":"Normal"}}
|
||||||
|
{"Key":":"}
|
||||||
|
{"Key":"%"}
|
||||||
|
{"Key":"s"}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"enter"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue