1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Python corrects the cursor column without taking 'virtualedit'
12 into account. (lilydjwg)
13 Solution: Call check_cursor_col_win().
14 Files: src/if_py_both.h, src/mbyte.c, src/misc2.c, src/normal.c,
15 src/proto/mbyte.pro, src/proto/misc2.pro
18 *** ../vim-7.3.238/src/if_py_both.h 2011-06-26 04:01:37.000000000 +0200
19 --- src/if_py_both.h 2011-07-07 14:28:19.000000000 +0200
27 if (!PyArg_Parse(val, "(ll)", &lnum, &col))
35 - /* When column is out of range silently correct it. */
36 - len = (long)STRLEN(ml_get_buf(this->win->w_buffer, lnum, FALSE));
40 this->win->w_cursor.lnum = lnum;
41 this->win->w_cursor.col = col;
42 #ifdef FEAT_VIRTUALEDIT
43 this->win->w_cursor.coladd = 0;
45 ! update_screen(VALID);
49 else if (strcmp(name, "height") == 0)
54 this->win->w_cursor.lnum = lnum;
55 this->win->w_cursor.col = col;
56 #ifdef FEAT_VIRTUALEDIT
57 this->win->w_cursor.coladd = 0;
59 ! /* When column is out of range silently correct it. */
60 ! check_cursor_col_win(this->win);
62 + update_screen(VALID);
65 else if (strcmp(name, "height") == 0)
66 *** ../vim-7.3.238/src/mbyte.c 2011-04-11 14:29:13.000000000 +0200
67 --- src/mbyte.c 2011-07-07 14:27:07.000000000 +0200
73 ! mb_adjustpos(&curwin->w_cursor);
81 ! mb_adjustpos(curbuf, &curwin->w_cursor);
87 * If it points to a tail byte it's moved backwards to the head byte.
95 * If it points to a tail byte it's moved backwards to the head byte.
98 ! mb_adjustpos(buf, lp)
108 ! p = ml_get(lp->lnum);
109 lp->col -= (*mb_head_off)(p, p + lp->col);
110 #ifdef FEAT_VIRTUALEDIT
111 /* Reset "coladd" when the cursor would be on the right half of a
116 ! p = ml_get_buf(buf, lp->lnum, FALSE);
117 lp->col -= (*mb_head_off)(p, p + lp->col);
118 #ifdef FEAT_VIRTUALEDIT
119 /* Reset "coladd" when the cursor would be on the right half of a
120 *** ../vim-7.3.238/src/misc2.c 2011-04-11 16:56:29.000000000 +0200
121 --- src/misc2.c 2011-07-07 14:27:50.000000000 +0200
125 /* prevent from moving onto a trail byte */
133 /* prevent from moving onto a trail byte */
135 ! mb_adjustpos(curbuf, pos);
145 #ifdef FEAT_VIRTUALEDIT
146 ! colnr_T oldcol = curwin->w_cursor.col;
147 ! colnr_T oldcoladd = curwin->w_cursor.col + curwin->w_cursor.coladd;
150 ! len = (colnr_T)STRLEN(ml_get_curline());
152 ! curwin->w_cursor.col = 0;
153 ! else if (curwin->w_cursor.col >= len)
155 /* Allow cursor past end-of-line when:
156 * - in Insert mode or restarting Insert mode
161 + check_cursor_col_win(curwin);
165 + * Make sure win->w_cursor.col is valid.
168 + check_cursor_col_win(win)
172 #ifdef FEAT_VIRTUALEDIT
173 ! colnr_T oldcol = win->w_cursor.col;
174 ! colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
177 ! len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE));
179 ! win->w_cursor.col = 0;
180 ! else if (win->w_cursor.col >= len)
182 /* Allow cursor past end-of-line when:
183 * - in Insert mode or restarting Insert mode
186 || (ve_flags & VE_ONEMORE)
189 ! curwin->w_cursor.col = len;
192 ! curwin->w_cursor.col = len - 1;
194 ! /* prevent cursor from moving on the trail byte */
196 ! mb_adjust_cursor();
200 ! else if (curwin->w_cursor.col < 0)
201 ! curwin->w_cursor.col = 0;
203 #ifdef FEAT_VIRTUALEDIT
204 /* If virtual editing is on, we can leave the cursor on the old position,
205 * only we must set it to virtual. But don't do it when at the end of the
207 if (oldcol == MAXCOL)
208 ! curwin->w_cursor.coladd = 0;
209 else if (ve_flags == VE_ALL)
211 ! if (oldcoladd > curwin->w_cursor.col)
212 ! curwin->w_cursor.coladd = oldcoladd - curwin->w_cursor.col;
214 /* avoid weird number when there is a miscalculation or overflow */
215 ! curwin->w_cursor.coladd = 0;
220 || (ve_flags & VE_ONEMORE)
223 ! win->w_cursor.col = len;
226 ! win->w_cursor.col = len - 1;
228 ! /* Move the cursor to the head byte. */
230 ! mb_adjustpos(win->w_buffer, &win->w_cursor);
234 ! else if (win->w_cursor.col < 0)
235 ! win->w_cursor.col = 0;
237 #ifdef FEAT_VIRTUALEDIT
238 /* If virtual editing is on, we can leave the cursor on the old position,
239 * only we must set it to virtual. But don't do it when at the end of the
241 if (oldcol == MAXCOL)
242 ! win->w_cursor.coladd = 0;
243 else if (ve_flags == VE_ALL)
245 ! if (oldcoladd > win->w_cursor.col)
246 ! win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
248 /* avoid weird number when there is a miscalculation or overflow */
249 ! win->w_cursor.coladd = 0;
253 *** ../vim-7.3.238/src/normal.c 2011-06-20 00:45:55.000000000 +0200
254 --- src/normal.c 2011-07-07 14:27:57.000000000 +0200
263 else if (pp->lnum > 1)
268 ! mb_adjustpos(curbuf, pp);
271 else if (pp->lnum > 1)
272 *** ../vim-7.3.238/src/proto/mbyte.pro 2010-08-15 21:57:28.000000000 +0200
273 --- src/proto/mbyte.pro 2011-07-07 14:27:09.000000000 +0200
276 int utf_valid_string __ARGS((char_u *s, char_u *end));
277 int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
278 void mb_adjust_cursor __ARGS((void));
279 ! void mb_adjustpos __ARGS((pos_T *lp));
280 char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
281 int mb_charlen __ARGS((char_u *str));
282 int mb_charlen_len __ARGS((char_u *str, int len));
284 int utf_valid_string __ARGS((char_u *s, char_u *end));
285 int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
286 void mb_adjust_cursor __ARGS((void));
287 ! void mb_adjustpos __ARGS((buf_T *buf, pos_T *lp));
288 char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
289 int mb_charlen __ARGS((char_u *str));
290 int mb_charlen_len __ARGS((char_u *str, int len));
291 *** ../vim-7.3.238/src/proto/misc2.pro 2011-04-11 16:56:29.000000000 +0200
292 --- src/proto/misc2.pro 2011-07-07 14:26:57.000000000 +0200
296 linenr_T get_cursor_rel_lnum __ARGS((win_T *wp, linenr_T lnum));
297 void check_cursor_lnum __ARGS((void));
298 void check_cursor_col __ARGS((void));
299 + void check_cursor_col_win __ARGS((win_T *win));
300 void check_cursor __ARGS((void));
301 void adjust_cursor_col __ARGS((void));
302 int leftcol_changed __ARGS((void));
303 *** ../vim-7.3.238/src/version.c 2011-07-07 15:04:38.000000000 +0200
304 --- src/version.c 2011-07-07 15:05:49.000000000 +0200
308 { /* Add new patch number below this line */
314 hundred-and-one symptoms of being an internet addict:
315 256. You are able to write down over 250 symptoms of being an internet
316 addict, even though they only asked for 101.
318 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
319 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
320 \\\ an exciting new programming language -- http://www.Zimbu.org ///
321 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///