mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-24 01:11:51 +00:00
Highlight find matches
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
34ed734749
commit
3abd7bc8dd
3 changed files with 21 additions and 11 deletions
|
@ -110,22 +110,23 @@ impl FindBar {
|
|||
) {
|
||||
if let Some(editor) = &self.active_editor {
|
||||
let search = self.query_editor.read(cx).text(cx);
|
||||
if search.is_empty() {
|
||||
return;
|
||||
}
|
||||
let search = AhoCorasick::new_auto_configured(&[search]);
|
||||
let theme = &self.settings.borrow().theme.find;
|
||||
editor.update(cx, |editor, cx| {
|
||||
if search.is_empty() {
|
||||
editor.clear_highlighted_ranges::<Self>(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let search = AhoCorasick::new_auto_configured(&[search]);
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
let mut ranges = search
|
||||
let ranges = search
|
||||
.stream_find_iter(buffer.bytes_in_range(0..buffer.len()))
|
||||
.map(|mat| {
|
||||
let mat = mat.unwrap();
|
||||
mat.start()..mat.end()
|
||||
buffer.anchor_after(mat.start())..buffer.anchor_before(mat.end())
|
||||
})
|
||||
.peekable();
|
||||
if ranges.peek().is_some() {
|
||||
editor.select_ranges(ranges, None, cx);
|
||||
}
|
||||
.collect();
|
||||
editor.highlight_ranges::<Self>(ranges, theme.match_background, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ pub struct Theme {
|
|||
pub project_panel: ProjectPanel,
|
||||
pub selector: Selector,
|
||||
pub editor: EditorStyle,
|
||||
pub find: Find,
|
||||
pub project_diagnostics: ProjectDiagnostics,
|
||||
}
|
||||
|
||||
|
@ -87,6 +88,11 @@ pub struct Tab {
|
|||
pub icon_conflict: Color,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Default)]
|
||||
pub struct Find {
|
||||
pub match_background: Color,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
pub struct Sidebar {
|
||||
#[serde(flatten)]
|
||||
|
|
|
@ -185,7 +185,7 @@ corner_radius = 6
|
|||
|
||||
[project_panel]
|
||||
extends = "$panel"
|
||||
padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2
|
||||
padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2
|
||||
|
||||
[project_panel.entry]
|
||||
text = "$text.1"
|
||||
|
@ -318,3 +318,6 @@ status_bar_item = { extends = "$text.2", margin.right = 10 }
|
|||
tab_icon_width = 13
|
||||
tab_icon_spacing = 4
|
||||
tab_summary_spacing = 10
|
||||
|
||||
[find]
|
||||
match_background = "$state.highlighted_line"
|
||||
|
|
Loading…
Reference in a new issue