diff options
author | Bram Moolenaar <Bram@vim.org> | 2011-07-07 15:08:58 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2011-07-07 15:08:58 +0200 |
commit | 03a807aaf45e5f85a10cd3b0c4e4913d170f8f5a (patch) | |
tree | 2a1889c39ffc1fcb52dd2950e9327fec7ee01648 /src/misc2.c | |
parent | 5cfe2d760db119718287ad3d4ee11d6914ceee58 (diff) | |
download | vim-git-03a807aaf45e5f85a10cd3b0c4e4913d170f8f5a.tar.gz |
updated for version 7.3.239v7.3.239
Problem: Python corrects the cursor column without taking 'virtualedit'
into account. (lilydjwg)
Solution: Call check_cursor_col_win().
Diffstat (limited to 'src/misc2.c')
-rw-r--r-- | src/misc2.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/misc2.c b/src/misc2.c index c6207ff04..9479a53c2 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -333,7 +333,7 @@ coladvance2(pos, addspaces, finetune, wcol) #ifdef FEAT_MBYTE /* prevent from moving onto a trail byte */ if (has_mbyte) - mb_adjustpos(pos); + mb_adjustpos(curbuf, pos); #endif if (col < wcol) @@ -544,16 +544,26 @@ check_cursor_lnum() void check_cursor_col() { + check_cursor_col_win(curwin); +} + +/* + * Make sure win->w_cursor.col is valid. + */ + void +check_cursor_col_win(win) + win_T *win; +{ colnr_T len; #ifdef FEAT_VIRTUALEDIT - colnr_T oldcol = curwin->w_cursor.col; - colnr_T oldcoladd = curwin->w_cursor.col + curwin->w_cursor.coladd; + colnr_T oldcol = win->w_cursor.col; + colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; #endif - len = (colnr_T)STRLEN(ml_get_curline()); + len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); if (len == 0) - curwin->w_cursor.col = 0; - else if (curwin->w_cursor.col >= len) + win->w_cursor.col = 0; + else if (win->w_cursor.col >= len) { /* Allow cursor past end-of-line when: * - in Insert mode or restarting Insert mode @@ -567,33 +577,33 @@ check_cursor_col() || (ve_flags & VE_ONEMORE) #endif || virtual_active()) - curwin->w_cursor.col = len; + win->w_cursor.col = len; else { - curwin->w_cursor.col = len - 1; + win->w_cursor.col = len - 1; #ifdef FEAT_MBYTE - /* prevent cursor from moving on the trail byte */ + /* Move the cursor to the head byte. */ if (has_mbyte) - mb_adjust_cursor(); + mb_adjustpos(win->w_buffer, &win->w_cursor); #endif } } - else if (curwin->w_cursor.col < 0) - curwin->w_cursor.col = 0; + else if (win->w_cursor.col < 0) + win->w_cursor.col = 0; #ifdef FEAT_VIRTUALEDIT /* If virtual editing is on, we can leave the cursor on the old position, * only we must set it to virtual. But don't do it when at the end of the * line. */ if (oldcol == MAXCOL) - curwin->w_cursor.coladd = 0; + win->w_cursor.coladd = 0; else if (ve_flags == VE_ALL) { - if (oldcoladd > curwin->w_cursor.col) - curwin->w_cursor.coladd = oldcoladd - curwin->w_cursor.col; + if (oldcoladd > win->w_cursor.col) + win->w_cursor.coladd = oldcoladd - win->w_cursor.col; else /* avoid weird number when there is a miscalculation or overflow */ - curwin->w_cursor.coladd = 0; + win->w_cursor.coladd = 0; } #endif } |