Center forward and backward jumps too.

This commit is contained in:
Blaž Hrastnik 2021-04-24 11:46:46 +09:00
parent 651d3dec83
commit 594575ba3f

View file

@ -1889,12 +1889,16 @@ pub fn match_brackets(cx: &mut Context) {
pub fn jump_forward(cx: &mut Context) { pub fn jump_forward(cx: &mut Context) {
let count = cx.count; let count = cx.count;
let view = cx.view(); let (view, doc) = cx.current();
if let Some((id, selection)) = view.jumps.forward(count) { if let Some((id, selection)) = view.jumps.forward(count) {
// TODO: position first_line so that main cursor is centered
view.first_line = 0;
view.doc = *id; view.doc = *id;
let selection = selection.clone();
let cursor = selection.cursor();
doc.set_selection(view.id, selection);
// TODO: extract this centering into a function to share with _goto?
let line = doc.text().char_to_line(cursor);
view.first_line = line.saturating_sub(view.area.height as usize / 2);
}; };
} }
@ -1903,11 +1907,13 @@ pub fn jump_backward(cx: &mut Context) {
let (view, doc) = cx.current(); let (view, doc) = cx.current();
if let Some((id, selection)) = view.jumps.backward(count) { if let Some((id, selection)) = view.jumps.backward(count) {
// TODO: position first_line so that main cursor is centered
view.first_line = 0;
view.doc = *id; view.doc = *id;
let selection = selection.clone(); let selection = selection.clone();
let cursor = selection.cursor();
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
// TODO: extract this centering into a function to share with _goto?
let line = doc.text().char_to_line(cursor);
view.first_line = line.saturating_sub(view.area.height as usize / 2);
}; };
} }