mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
vim: Fix %s replace not working more than twice (#12045)
close: #11981 Release Notes: - N/A --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
f2357c71e1
commit
1e18bcb949
@ -9983,6 +9983,10 @@ impl Editor {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear_search_within_ranges(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
self.clear_background_highlights::<SearchWithinRange>(cx);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn highlight_background<T: 'static>(
|
pub fn highlight_background<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ranges: &[Range<Anchor>],
|
ranges: &[Range<Anchor>],
|
||||||
|
@ -353,7 +353,6 @@ fn replace_command(
|
|||||||
let range = snapshot
|
let range = snapshot
|
||||||
.anchor_before(Point::new(range.start.saturating_sub(1) as u32, 0))
|
.anchor_before(Point::new(range.start.saturating_sub(1) as u32, 0))
|
||||||
..snapshot.anchor_before(Point::new(range.end as u32, 0));
|
..snapshot.anchor_before(Point::new(range.end as u32, 0));
|
||||||
|
|
||||||
editor.set_search_within_ranges(&[range], cx)
|
editor.set_search_within_ranges(&[range], cx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -394,9 +393,7 @@ fn replace_command(
|
|||||||
.timer(Duration::from_millis(200))
|
.timer(Duration::from_millis(200))
|
||||||
.await;
|
.await;
|
||||||
editor
|
editor
|
||||||
.update(&mut cx, |editor, cx| {
|
.update(&mut cx, |editor, cx| editor.clear_search_within_ranges(cx))
|
||||||
editor.set_search_within_ranges(&[], cx)
|
|
||||||
})
|
|
||||||
.ok();
|
.ok();
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
@ -512,6 +509,8 @@ fn parse_replace_all(query: &str) -> Replacement {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use editor::{display_map::DisplayRow, DisplayPoint};
|
use editor::{display_map::DisplayRow, DisplayPoint};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use search::BufferSearchBar;
|
use search::BufferSearchBar;
|
||||||
@ -744,5 +743,19 @@ mod test {
|
|||||||
a
|
a
|
||||||
"
|
"
|
||||||
});
|
});
|
||||||
|
cx.executor().advance_clock(Duration::from_millis(250));
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
cx.simulate_shared_keystrokes("/ a enter").await;
|
||||||
|
cx.shared_state().await.assert_eq(indoc! {
|
||||||
|
"a
|
||||||
|
b
|
||||||
|
b
|
||||||
|
b
|
||||||
|
b
|
||||||
|
ˇa
|
||||||
|
a
|
||||||
|
"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,3 +10,7 @@
|
|||||||
{"Key":"b"}
|
{"Key":"b"}
|
||||||
{"Key":"enter"}
|
{"Key":"enter"}
|
||||||
{"Get":{"state":"a\nb\nb\nb\nˇb\na\na\n ","mode":"Normal"}}
|
{"Get":{"state":"a\nb\nb\nb\nˇb\na\na\n ","mode":"Normal"}}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"a"}
|
||||||
|
{"Key":"enter"}
|
||||||
|
{"Get":{"state":"a\nb\nb\nb\nb\nˇa\na\n ","mode":"Normal"}}
|
||||||
|
Loading…
Reference in New Issue
Block a user