on master help sign in
Rewrite goto_buffer
7b65a6dBlaž Hrastnik
helix-term/src/commands.rs+20−14
@@ -530,22 +530,28 @@ fn goto_previous_buffer(cx: &mut Context) {
530}
530}
531
531
532fn goto_buffer(cx: &mut Context, direction: Direction) {
532fn goto_buffer(cx: &mut Context, direction: Direction) {
533− let buf_cur = current!(cx.editor).1.id();
533+ let current = view!(cx.editor).doc;
534
534
535− if let Some(pos) = cx.editor.documents.iter().position(|(id, _)| id == buf_cur) {
535+ let id = match direction {
536− let goto_id = if direction == Direction::Forward {
536+ Direction::Forward => {
537− if pos < cx.editor.documents.iter().count() - 1 {
537+ let iter = cx.editor.documents.keys();
538− cx.editor.documents.iter().nth(pos + 1).unwrap().0
538+ let mut iter = iter.skip_while(|id| *id != &current);
539− } else {
539+ iter.next(); // skip current item
540− cx.editor.documents.iter().next().unwrap().0
540+ iter.next().or_else(|| cx.editor.documents.keys().next())
541− }
541+ }
542− } else if pos > 0 {
542+ Direction::Backward => {
543− cx.editor.documents.iter().nth(pos - 1).unwrap().0
543+ let iter = cx.editor.documents.keys();
544− } else {
544+ let mut iter = iter.rev().skip_while(|id| *id != &current);
545+ iter.next(); // skip current item
546+ iter.next()
545− cx.editor.documents.iter().last().unwrap().0
547+ .or_else(|| cx.editor.documents.keys().rev().next())
546− };
548+ }
547− cx.editor.switch(goto_id, Action::Replace);
548 }
549 }
550+ .unwrap();
551+
552+ let id = *id;
553+
554+ cx.editor.switch(id, Action::Replace);
549}
555}
550
556
551fn extend_to_line_start(cx: &mut Context) {
557fn extend_to_line_start(cx: &mut Context) {