@@ -2272,7 +2272,7 @@ undo_time(
22722272 long closest_start ;
22732273 long closest_seq = 0 ;
22742274 long val ;
2275- u_header_T * uhp ;
2275+ u_header_T * uhp = NULL ;
22762276 u_header_T * last ;
22772277 int mark ;
22782278 int nomark ;
@@ -2295,14 +2295,7 @@ undo_time(
22952295 * Init "closest" to a value we can't reach. */
22962296 if (absolute )
22972297 {
2298- if (step == 0 )
2299- {
2300- /* target 0 does not exist, got to 1 and above it. */
2301- target = 1 ;
2302- above = TRUE;
2303- }
2304- else
2305- target = step ;
2298+ target = step ;
23062299 closest = -1 ;
23072300 }
23082301 else
@@ -2369,6 +2362,10 @@ undo_time(
23692362 closest_start = closest ;
23702363 closest_seq = curbuf -> b_u_seq_cur ;
23712364
2365+ /* When "target" is 0; Back to origin. */
2366+ if (target == 0 )
2367+ goto found ;
2368+
23722369 /*
23732370 * May do this twice:
23742371 * 1. Search for "target", update "closest" to the best match found.
@@ -2494,8 +2491,9 @@ undo_time(
24942491 above = TRUE; /* stop above the header */
24952492 }
24962493
2494+ found :
24972495 /* If we found it: Follow the path to go to where we want to be. */
2498- if (uhp != NULL )
2496+ if (uhp != NULL || target == 0 )
24992497 {
25002498 /*
25012499 * First go up the tree as much as needed.
@@ -2510,87 +2508,93 @@ undo_time(
25102508 uhp = curbuf -> b_u_newhead ;
25112509 else
25122510 uhp = uhp -> uh_next .ptr ;
2513- if (uhp == NULL || uhp -> uh_walk != mark
2511+ if (uhp == NULL || ( target > 0 && uhp -> uh_walk != mark )
25142512 || (uhp -> uh_seq == target && !above ))
25152513 break ;
25162514 curbuf -> b_u_curhead = uhp ;
25172515 u_undoredo (TRUE);
2518- uhp -> uh_walk = nomark ; /* don't go back down here */
2516+ if (target > 0 )
2517+ uhp -> uh_walk = nomark ; /* don't go back down here */
25192518 }
25202519
2521- /*
2522- * And now go down the tree (redo), branching off where needed.
2523- */
2524- while (!got_int )
2520+ /* When back to origin, redo is not needed. */
2521+ if (target > 0 )
25252522 {
2526- /* Do the change warning now, for the same reason as above. */
2527- change_warning (0 );
2523+ /*
2524+ * And now go down the tree (redo), branching off where needed.
2525+ */
2526+ while (!got_int )
2527+ {
2528+ /* Do the change warning now, for the same reason as above. */
2529+ change_warning (0 );
25282530
2529- uhp = curbuf -> b_u_curhead ;
2530- if (uhp == NULL )
2531- break ;
2531+ uhp = curbuf -> b_u_curhead ;
2532+ if (uhp == NULL )
2533+ break ;
25322534
2533- /* Go back to the first branch with a mark. */
2534- while (uhp -> uh_alt_prev .ptr != NULL
2535+ /* Go back to the first branch with a mark. */
2536+ while (uhp -> uh_alt_prev .ptr != NULL
25352537 && uhp -> uh_alt_prev .ptr -> uh_walk == mark )
2536- uhp = uhp -> uh_alt_prev .ptr ;
2538+ uhp = uhp -> uh_alt_prev .ptr ;
25372539
2538- /* Find the last branch with a mark, that's the one. */
2539- last = uhp ;
2540- while (last -> uh_alt_next .ptr != NULL
2540+ /* Find the last branch with a mark, that's the one. */
2541+ last = uhp ;
2542+ while (last -> uh_alt_next .ptr != NULL
25412543 && last -> uh_alt_next .ptr -> uh_walk == mark )
2542- last = last -> uh_alt_next .ptr ;
2543- if (last != uhp )
2544- {
2545- /* Make the used branch the first entry in the list of
2546- * alternatives to make "u" and CTRL-R take this branch. */
2547- while (uhp -> uh_alt_prev .ptr != NULL )
2548- uhp = uhp -> uh_alt_prev .ptr ;
2549- if (last -> uh_alt_next .ptr != NULL )
2550- last -> uh_alt_next .ptr -> uh_alt_prev .ptr =
2544+ last = last -> uh_alt_next .ptr ;
2545+ if (last != uhp )
2546+ {
2547+ /* Make the used branch the first entry in the list of
2548+ * alternatives to make "u" and CTRL-R take this branch. */
2549+ while (uhp -> uh_alt_prev .ptr != NULL )
2550+ uhp = uhp -> uh_alt_prev .ptr ;
2551+ if (last -> uh_alt_next .ptr != NULL )
2552+ last -> uh_alt_next .ptr -> uh_alt_prev .ptr =
25512553 last -> uh_alt_prev .ptr ;
2552- last -> uh_alt_prev .ptr -> uh_alt_next .ptr = last -> uh_alt_next .ptr ;
2553- last -> uh_alt_prev .ptr = NULL ;
2554- last -> uh_alt_next .ptr = uhp ;
2555- uhp -> uh_alt_prev .ptr = last ;
2556-
2557- if (curbuf -> b_u_oldhead == uhp )
2558- curbuf -> b_u_oldhead = last ;
2559- uhp = last ;
2560- if (uhp -> uh_next .ptr != NULL )
2561- uhp -> uh_next .ptr -> uh_prev .ptr = uhp ;
2562- }
2563- curbuf -> b_u_curhead = uhp ;
2554+ last -> uh_alt_prev .ptr -> uh_alt_next .ptr =
2555+ last -> uh_alt_next .ptr ;
2556+ last -> uh_alt_prev .ptr = NULL ;
2557+ last -> uh_alt_next .ptr = uhp ;
2558+ uhp -> uh_alt_prev .ptr = last ;
2559+
2560+ if (curbuf -> b_u_oldhead == uhp )
2561+ curbuf -> b_u_oldhead = last ;
2562+ uhp = last ;
2563+ if (uhp -> uh_next .ptr != NULL )
2564+ uhp -> uh_next .ptr -> uh_prev .ptr = uhp ;
2565+ }
2566+ curbuf -> b_u_curhead = uhp ;
25642567
2565- if (uhp -> uh_walk != mark )
2566- break ; /* must have reached the target */
2568+ if (uhp -> uh_walk != mark )
2569+ break ; /* must have reached the target */
25672570
2568- /* Stop when going backwards in time and didn't find the exact
2569- * header we were looking for. */
2570- if (uhp -> uh_seq == target && above )
2571- {
2572- curbuf -> b_u_seq_cur = target - 1 ;
2573- break ;
2574- }
2571+ /* Stop when going backwards in time and didn't find the exact
2572+ * header we were looking for. */
2573+ if (uhp -> uh_seq == target && above )
2574+ {
2575+ curbuf -> b_u_seq_cur = target - 1 ;
2576+ break ;
2577+ }
25752578
2576- u_undoredo (FALSE);
2579+ u_undoredo (FALSE);
25772580
2578- /* Advance "curhead" to below the header we last used. If it
2579- * becomes NULL then we need to set "newhead" to this leaf. */
2580- if (uhp -> uh_prev .ptr == NULL )
2581- curbuf -> b_u_newhead = uhp ;
2582- curbuf -> b_u_curhead = uhp -> uh_prev .ptr ;
2583- did_undo = FALSE;
2581+ /* Advance "curhead" to below the header we last used. If it
2582+ * becomes NULL then we need to set "newhead" to this leaf. */
2583+ if (uhp -> uh_prev .ptr == NULL )
2584+ curbuf -> b_u_newhead = uhp ;
2585+ curbuf -> b_u_curhead = uhp -> uh_prev .ptr ;
2586+ did_undo = FALSE;
25842587
2585- if (uhp -> uh_seq == target ) /* found it! */
2586- break ;
2588+ if (uhp -> uh_seq == target ) /* found it! */
2589+ break ;
25872590
2588- uhp = uhp -> uh_prev .ptr ;
2589- if (uhp == NULL || uhp -> uh_walk != mark )
2590- {
2591- /* Need to redo more but can't find it... */
2592- internal_error ("undo_time()" );
2593- break ;
2591+ uhp = uhp -> uh_prev .ptr ;
2592+ if (uhp == NULL || uhp -> uh_walk != mark )
2593+ {
2594+ /* Need to redo more but can't find it... */
2595+ internal_error ("undo_time()" );
2596+ break ;
2597+ }
25942598 }
25952599 }
25962600 }
0 commit comments