@@ -2789,35 +2789,28 @@ fn exit_select_mode(cx: &mut Context) {
2789
2789
}
2790
2790
}
2791
2791
2792
- fn goto_pos ( editor : & mut Editor , pos : usize ) {
2793
- let ( view, doc) = current ! ( editor) ;
2794
-
2795
- push_jump ( view, doc) ;
2796
- doc. set_selection ( view. id , Selection :: point ( pos) ) ;
2797
- align_view ( doc, view, Align :: Center ) ;
2798
- }
2799
-
2800
2792
fn goto_first_diag ( cx : & mut Context ) {
2801
- let doc = doc ! ( cx. editor) ;
2802
- let pos = match doc. diagnostics ( ) . first ( ) {
2803
- Some ( diag) => diag. range . start ,
2793
+ let ( view , doc) = current ! ( cx. editor) ;
2794
+ let selection = match doc. diagnostics ( ) . first ( ) {
2795
+ Some ( diag) => Selection :: single ( diag. range . start , diag . range . end ) ,
2804
2796
None => return ,
2805
2797
} ;
2806
- goto_pos ( cx. editor , pos) ;
2798
+ doc. set_selection ( view. id , selection) ;
2799
+ align_view ( doc, view, Align :: Center ) ;
2807
2800
}
2808
2801
2809
2802
fn goto_last_diag ( cx : & mut Context ) {
2810
- let doc = doc ! ( cx. editor) ;
2811
- let pos = match doc. diagnostics ( ) . last ( ) {
2812
- Some ( diag) => diag. range . start ,
2803
+ let ( view , doc) = current ! ( cx. editor) ;
2804
+ let selection = match doc. diagnostics ( ) . last ( ) {
2805
+ Some ( diag) => Selection :: single ( diag. range . start , diag . range . end ) ,
2813
2806
None => return ,
2814
2807
} ;
2815
- goto_pos ( cx. editor , pos) ;
2808
+ doc. set_selection ( view. id , selection) ;
2809
+ align_view ( doc, view, Align :: Center ) ;
2816
2810
}
2817
2811
2818
2812
fn goto_next_diag ( cx : & mut Context ) {
2819
- let editor = & mut cx. editor ;
2820
- let ( view, doc) = current ! ( editor) ;
2813
+ let ( view, doc) = current ! ( cx. editor) ;
2821
2814
2822
2815
let cursor_pos = doc
2823
2816
. selection ( view. id )
@@ -2830,17 +2823,16 @@ fn goto_next_diag(cx: &mut Context) {
2830
2823
. find ( |diag| diag. range . start > cursor_pos)
2831
2824
. or_else ( || doc. diagnostics ( ) . first ( ) ) ;
2832
2825
2833
- let pos = match diag {
2834
- Some ( diag) => diag. range . start ,
2826
+ let selection = match diag {
2827
+ Some ( diag) => Selection :: single ( diag. range . start , diag . range . end ) ,
2835
2828
None => return ,
2836
2829
} ;
2837
-
2838
- goto_pos ( editor , pos ) ;
2830
+ doc . set_selection ( view . id , selection ) ;
2831
+ align_view ( doc , view , Align :: Center ) ;
2839
2832
}
2840
2833
2841
2834
fn goto_prev_diag ( cx : & mut Context ) {
2842
- let editor = & mut cx. editor ;
2843
- let ( view, doc) = current ! ( editor) ;
2835
+ let ( view, doc) = current ! ( cx. editor) ;
2844
2836
2845
2837
let cursor_pos = doc
2846
2838
. selection ( view. id )
@@ -2854,12 +2846,14 @@ fn goto_prev_diag(cx: &mut Context) {
2854
2846
. find ( |diag| diag. range . start < cursor_pos)
2855
2847
. or_else ( || doc. diagnostics ( ) . last ( ) ) ;
2856
2848
2857
- let pos = match diag {
2858
- Some ( diag) => diag. range . start ,
2849
+ let selection = match diag {
2850
+ // NOTE: the selection is reversed because we're jumping to the
2851
+ // previous diagnostic.
2852
+ Some ( diag) => Selection :: single ( diag. range . end , diag. range . start ) ,
2859
2853
None => return ,
2860
2854
} ;
2861
-
2862
- goto_pos ( editor , pos ) ;
2855
+ doc . set_selection ( view . id , selection ) ;
2856
+ align_view ( doc , view , Align :: Center ) ;
2863
2857
}
2864
2858
2865
2859
fn goto_first_change ( cx : & mut Context ) {
0 commit comments