@@ -3439,48 +3439,55 @@ fn goto_last_diag(cx: &mut Context) {
34393439}
34403440
34413441fn goto_next_diag ( cx : & mut Context ) {
3442- let ( view, doc) = current ! ( cx. editor) ;
3442+ let motion = move |editor : & mut Editor | {
3443+ let ( view, doc) = current ! ( editor) ;
34433444
3444- let cursor_pos = doc
3445- . selection ( view. id )
3446- . primary ( )
3447- . cursor ( doc. text ( ) . slice ( ..) ) ;
3445+ let cursor_pos = doc
3446+ . selection ( view. id )
3447+ . primary ( )
3448+ . cursor ( doc. text ( ) . slice ( ..) ) ;
34483449
3449- let diag = doc
3450- . diagnostics ( )
3451- . iter ( )
3452- . find ( |diag| diag. range . start > cursor_pos)
3453- . or_else ( || doc. diagnostics ( ) . first ( ) ) ;
3450+ let diag = doc
3451+ . diagnostics ( )
3452+ . iter ( )
3453+ . find ( |diag| diag. range . start > cursor_pos)
3454+ . or_else ( || doc. diagnostics ( ) . first ( ) ) ;
34543455
3455- let selection = match diag {
3456- Some ( diag) => Selection :: single ( diag. range . start , diag. range . end ) ,
3457- None => return ,
3456+ let selection = match diag {
3457+ Some ( diag) => Selection :: single ( diag. range . start , diag. range . end ) ,
3458+ None => return ,
3459+ } ;
3460+ doc. set_selection ( view. id , selection) ;
34583461 } ;
3459- doc. set_selection ( view. id , selection) ;
3462+
3463+ cx. editor . apply_motion ( motion) ;
34603464}
34613465
34623466fn goto_prev_diag ( cx : & mut Context ) {
3463- let ( view, doc) = current ! ( cx. editor) ;
3467+ let motion = move |editor : & mut Editor | {
3468+ let ( view, doc) = current ! ( editor) ;
34643469
3465- let cursor_pos = doc
3466- . selection ( view. id )
3467- . primary ( )
3468- . cursor ( doc. text ( ) . slice ( ..) ) ;
3470+ let cursor_pos = doc
3471+ . selection ( view. id )
3472+ . primary ( )
3473+ . cursor ( doc. text ( ) . slice ( ..) ) ;
34693474
3470- let diag = doc
3471- . diagnostics ( )
3472- . iter ( )
3473- . rev ( )
3474- . find ( |diag| diag. range . start < cursor_pos)
3475- . or_else ( || doc. diagnostics ( ) . last ( ) ) ;
3476-
3477- let selection = match diag {
3478- // NOTE: the selection is reversed because we're jumping to the
3479- // previous diagnostic.
3480- Some ( diag) => Selection :: single ( diag. range . end , diag. range . start ) ,
3481- None => return ,
3475+ let diag = doc
3476+ . diagnostics ( )
3477+ . iter ( )
3478+ . rev ( )
3479+ . find ( |diag| diag. range . start < cursor_pos)
3480+ . or_else ( || doc. diagnostics ( ) . last ( ) ) ;
3481+
3482+ let selection = match diag {
3483+ // NOTE: the selection is reversed because we're jumping to the
3484+ // previous diagnostic.
3485+ Some ( diag) => Selection :: single ( diag. range . end , diag. range . start ) ,
3486+ None => return ,
3487+ } ;
3488+ doc. set_selection ( view. id , selection) ;
34823489 } ;
3483- doc . set_selection ( view . id , selection ) ;
3490+ cx . editor . apply_motion ( motion )
34843491}
34853492
34863493fn goto_first_change ( cx : & mut Context ) {
0 commit comments