aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorCossonLeo2021-11-09 02:11:45 +0000
committerGitHub2021-11-09 02:11:45 +0000
commita69caff450ff8201e16d0a0b4617114e03ed3c97 (patch)
treedc33ad1996083c776234645cf4afd30167c2a136 /helix-term
parentf96be0fcbc69e7a2fd6cb4ccd16ae99002109893 (diff)
search_impl will only align cursor center when it isn't in view (#959)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 245fbe4e..42163b8e 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1175,6 +1175,7 @@ fn search_impl(
regex: &Regex,
movement: Movement,
direction: Direction,
+ scrolloff: usize,
) {
let text = doc.text().slice(..);
let selection = doc.selection(view.id);
@@ -1233,7 +1234,11 @@ fn search_impl(
};
doc.set_selection(view.id, selection);
- align_view(doc, view, Align::Center);
+ if view.is_cursor_in_view(doc, 0) {
+ view.ensure_cursor_in_view(doc, scrolloff);
+ } else {
+ align_view(doc, view, Align::Center)
+ }
};
}
@@ -1257,6 +1262,8 @@ fn rsearch(cx: &mut Context) {
// TODO: use one function for search vs extend
fn searcher(cx: &mut Context, direction: Direction) {
let reg = cx.register.unwrap_or('/');
+ let scrolloff = cx.editor.config.scrolloff;
+
let (_, doc) = current!(cx.editor);
// TODO: could probably share with select_on_matches?
@@ -1281,7 +1288,15 @@ fn searcher(cx: &mut Context, direction: Direction) {
if event != PromptEvent::Update {
return;
}
- search_impl(doc, view, &contents, &regex, Movement::Move, direction);
+ search_impl(
+ doc,
+ view,
+ &contents,
+ &regex,
+ Movement::Move,
+ direction,
+ scrolloff,
+ );
},
);
@@ -1289,6 +1304,7 @@ fn searcher(cx: &mut Context, direction: Direction) {
}
fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) {
+ let scrolloff = cx.editor.config.scrolloff;
let (view, doc) = current!(cx.editor);
let registers = &cx.editor.registers;
if let Some(query) = registers.read('/') {
@@ -1303,7 +1319,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
.case_insensitive(case_insensitive)
.build()
{
- search_impl(doc, view, &contents, &regex, movement, direction);
+ search_impl(doc, view, &contents, &regex, movement, direction, scrolloff);
} else {
// get around warning `mutable_borrow_reservation_conflict`
// which will be a hard error in the future