Skip to content

Commit cfb43ac

Browse files
authored
Merge pull request #200 from patch0/dont-search-for-empty-strings
Return early from various search functions when the target is empty
2 parents 4a2ef25 + 2c6167c commit cfb43ac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/editor/scanning.rs

+17
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ impl Editor {
7777
}
7878
}
7979

80+
// If no target is given, do nothing
81+
if target.is_empty() {
82+
return Ok(());
83+
}
84+
8085
// Main body of the search feature
8186
let mut done = false;
8287
let Size { w, h } = size()?;
@@ -127,6 +132,10 @@ impl Editor {
127132

128133
/// Move to the next match
129134
pub fn next_match(&mut self, target: &str) -> Option<String> {
135+
if target.is_empty() {
136+
return None;
137+
}
138+
130139
if let Some(doc) = self.try_doc_mut() {
131140
let mtch = doc.next_match(target, 1)?;
132141
// Select match
@@ -145,6 +154,10 @@ impl Editor {
145154

146155
/// Move to the previous match
147156
pub fn prev_match(&mut self, target: &str) -> Option<String> {
157+
if target.is_empty() {
158+
return None;
159+
}
160+
148161
if let Some(doc) = self.try_doc_mut() {
149162
let mtch = doc.prev_match(target)?;
150163
doc.move_to(&mtch.loc);
@@ -172,6 +185,10 @@ impl Editor {
172185
let editor_bg = Bg(config!(self.config, colors).editor_bg.to_color()?);
173186
// Request replace information
174187
let target = self.prompt("Replace")?;
188+
// If no target is given, do nothing
189+
if target.is_empty() {
190+
return Ok(());
191+
}
175192
let into = self.prompt("With")?;
176193
let mut done = false;
177194
let Size { w, h } = size()?;

0 commit comments

Comments
 (0)