Add center_on_match option for search (#40523)
[Closes discussion #28943](https://github.com/zed-industries/zed/discussions/28943) Release Notes: - Added `center_on_match` option to center matched text in view during buffer or project search. --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
co-authored by
Smit Barmase
parent
42149df0f2
commit
2131d88e48
@@ -159,6 +159,7 @@ pub struct SearchSettings {
|
||||
pub case_sensitive: bool,
|
||||
pub include_ignored: bool,
|
||||
pub regex: bool,
|
||||
pub center_on_match: bool,
|
||||
}
|
||||
|
||||
impl EditorSettings {
|
||||
@@ -249,6 +250,7 @@ impl Settings for EditorSettings {
|
||||
case_sensitive: search.case_sensitive.unwrap(),
|
||||
include_ignored: search.include_ignored.unwrap(),
|
||||
regex: search.regex.unwrap(),
|
||||
center_on_match: search.center_on_match.unwrap(),
|
||||
},
|
||||
auto_signature_help: editor.auto_signature_help.unwrap(),
|
||||
show_signature_help_after_edits: editor.show_signature_help_after_edits.unwrap(),
|
||||
|
||||
@@ -1593,7 +1593,12 @@ impl SearchableItem for Editor {
|
||||
) {
|
||||
self.unfold_ranges(&[matches[index].clone()], false, true, cx);
|
||||
let range = self.range_for_match(&matches[index], collapse);
|
||||
self.change_selections(Default::default(), window, cx, |s| {
|
||||
let autoscroll = if EditorSettings::get_global(cx).search.center_on_match {
|
||||
Autoscroll::center()
|
||||
} else {
|
||||
Autoscroll::fit()
|
||||
};
|
||||
self.change_selections(SelectionEffects::scroll(autoscroll), window, cx, |s| {
|
||||
s.select_ranges([range]);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user