Rewrite goto_buffer

pull/975/head
Blaž Hrastnik 3 years ago
parent 78c68fae91
commit 7b65a6d687

@ -530,22 +530,28 @@ fn goto_previous_buffer(cx: &mut Context) {
} }
fn goto_buffer(cx: &mut Context, direction: Direction) { fn goto_buffer(cx: &mut Context, direction: Direction) {
let buf_cur = current!(cx.editor).1.id(); let current = view!(cx.editor).doc;
if let Some(pos) = cx.editor.documents.iter().position(|(id, _)| id == buf_cur) { let id = match direction {
let goto_id = if direction == Direction::Forward { Direction::Forward => {
if pos < cx.editor.documents.iter().count() - 1 { let iter = cx.editor.documents.keys();
cx.editor.documents.iter().nth(pos + 1).unwrap().0 let mut iter = iter.skip_while(|id| *id != &current);
} else { iter.next(); // skip current item
cx.editor.documents.iter().next().unwrap().0 iter.next().or_else(|| cx.editor.documents.keys().next())
} }
} else if pos > 0 { Direction::Backward => {
cx.editor.documents.iter().nth(pos - 1).unwrap().0 let iter = cx.editor.documents.keys();
} else { let mut iter = iter.rev().skip_while(|id| *id != &current);
cx.editor.documents.iter().last().unwrap().0 iter.next(); // skip current item
}; iter.next()
cx.editor.switch(goto_id, Action::Replace); .or_else(|| cx.editor.documents.keys().rev().next())
}
} }
.unwrap();
let id = *id;
cx.editor.switch(id, Action::Replace);
} }
fn extend_to_line_start(cx: &mut Context) { fn extend_to_line_start(cx: &mut Context) {

Loading…
Cancel
Save