diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-08-04 14:29:54 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-08-04 14:29:54 +0200 |
commit | f9bb734367d9a706cc53cc30bbcb3544bfb16cc5 (patch) | |
tree | 032c872f2bc8cf52ec4b9a303169b396927d2568 /src/undo.c | |
parent | 006d2b036bfa865f1bb6920fb97bda4e412d0080 (diff) | |
download | vim-git-f9bb734367d9a706cc53cc30bbcb3544bfb16cc5.tar.gz |
When undoing a reload, move the cursor to the first changed line.
Diffstat (limited to 'src/undo.c')
-rw-r--r-- | src/undo.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/undo.c b/src/undo.c index eb887d8b7..1b7419725 100644 --- a/src/undo.c +++ b/src/undo.c @@ -2923,6 +2923,42 @@ u_unchanged(buf) } /* + * After reloading a buffer which was saved for 'undoreload': Find the first + * line that was changed and set the cursor there. + */ + void +u_find_first_changed() +{ + u_header_T *uhp = curbuf->b_u_newhead; + u_entry_T *uep; + linenr_T lnum; + + if (curbuf->b_u_curhead != NULL || uhp == NULL) + return; /* undid something in an autocmd? */ + + /* Check that the last undo block was for the whole file. */ + uep = uhp->uh_entry; + if (uep->ue_top != 0 || uep->ue_bot != 0) + return; + + for (lnum = 1; lnum < curbuf->b_ml.ml_line_count + && lnum <= uep->ue_size; ++lnum) + if (STRCMP(ml_get_buf(curbuf, lnum, FALSE), + uep->ue_array[lnum - 1]) != 0) + { + clearpos(&(uhp->uh_cursor)); + uhp->uh_cursor.lnum = lnum; + return; + } + if (curbuf->b_ml.ml_line_count != uep->ue_size) + { + /* lines added or deleted at the end, put the cursor there */ + clearpos(&(uhp->uh_cursor)); + uhp->uh_cursor.lnum = lnum; + } +} + +/* * Increase the write count, store it in the last undo header, what would be * used for "u". */ |