To: vim-dev@vim.org Subject: Patch 6.1.360 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.360 (depends on 6.1.341) Problem: In Insert mode CTRL-K ESC messes up a multi-byte character. (Anders Helmersson) Solution: Save all bytes of a character when displaying a character temporarily. Files: src/edit.c, src/proto/screen.pro, src/screen.c *** ../vim61.359/src/edit.c Mon Feb 24 11:29:14 2003 --- src/edit.c Tue Feb 25 20:47:08 2003 *************** *** 1367,1376 **** * Put a character directly onto the screen. It's not stored in a buffer. * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. */ ! static int pc_char; ! #define PC_CHAR_UNSET 0 /* pc_char was not set */ ! #define PC_CHAR_RIGHT 1 /* right halve of double-wide char */ ! #define PC_CHAR_LEFT 2 /* left halve of double-wide char */ static int pc_attr; static int pc_row; static int pc_col; --- 1367,1382 ---- * Put a character directly onto the screen. It's not stored in a buffer. * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. */ ! static int pc_status; ! #define PC_STATUS_UNSET 0 /* pc_bytes was not set */ ! #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */ ! #define PC_STATUS_LEFT 2 /* left halve of double-wide char */ ! #define PC_STATUS_SET 3 /* pc_bytes was filled */ ! #ifdef FEAT_MBYTE ! static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */ ! #else ! static char_u pc_bytes[2]; /* saved bytes */ ! #endif static int pc_attr; static int pc_row; static int pc_col; *************** *** 1393,1399 **** pc_row = W_WINROW(curwin) + curwin->w_wrow; pc_col = W_WINCOL(curwin); #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE) ! pc_char = PC_CHAR_UNSET; #endif #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) --- 1399,1405 ---- pc_row = W_WINROW(curwin) + curwin->w_wrow; pc_col = W_WINCOL(curwin); #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE) ! pc_status = PC_STATUS_UNSET; #endif #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) *************** *** 1408,1414 **** { screen_putchar(' ', pc_row, fix_col, attr); --curwin->w_wcol; ! pc_char = PC_CHAR_RIGHT; } } # endif --- 1414,1420 ---- { screen_putchar(' ', pc_row, fix_col, attr); --curwin->w_wcol; ! pc_status = PC_STATUS_RIGHT; } } # endif *************** *** 1419,1433 **** pc_col += curwin->w_wcol; #ifdef FEAT_MBYTE if (mb_lefthalve(pc_row, pc_col)) ! pc_char = PC_CHAR_LEFT; #endif } /* save the character to be able to put it back */ #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE) ! if (pc_char == PC_CHAR_UNSET) #endif ! pc_char = screen_getchar(pc_row, pc_col, &pc_attr); screen_putchar(c, pc_row, pc_col, attr); } } --- 1425,1442 ---- pc_col += curwin->w_wcol; #ifdef FEAT_MBYTE if (mb_lefthalve(pc_row, pc_col)) ! pc_status = PC_STATUS_LEFT; #endif } /* save the character to be able to put it back */ #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE) ! if (pc_status == PC_STATUS_UNSET) #endif ! { ! screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr); ! pc_status = PC_STATUS_SET; ! } screen_putchar(c, pc_row, pc_col, attr); } } *************** *** 1438,1453 **** void edit_unputchar() { ! if (pc_char != PC_CHAR_UNSET && pc_row >= msg_scrolled) { #if defined(FEAT_MBYTE) ! if (pc_char == PC_CHAR_RIGHT) ++curwin->w_wcol; ! if (pc_char == PC_CHAR_RIGHT || pc_char == PC_CHAR_LEFT) redrawWinline(curwin->w_cursor.lnum, FALSE); else #endif ! screen_putchar(pc_char, pc_row - msg_scrolled, pc_col, pc_attr); } } --- 1447,1462 ---- void edit_unputchar() { ! if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled) { #if defined(FEAT_MBYTE) ! if (pc_status == PC_STATUS_RIGHT) ++curwin->w_wcol; ! if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT) redrawWinline(curwin->w_cursor.lnum, FALSE); else #endif ! screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr); } } *************** *** 5709,5715 **** /* * If we are going to wait for a character, show a '"'. */ ! pc_char = PC_CHAR_UNSET; if (redrawing() && !char_avail()) { /* may need to redraw when no more chars available now */ --- 5718,5724 ---- /* * If we are going to wait for a character, show a '"'. */ ! pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { /* may need to redraw when no more chars available now */ *************** *** 7186,7192 **** int c; int cc; ! pc_char = PC_CHAR_UNSET; if (redrawing() && !char_avail()) { /* may need to redraw when no more chars available now */ --- 7195,7201 ---- int c; int cc; ! pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { /* may need to redraw when no more chars available now */ *** ../vim61.359/src/proto/screen.pro Fri Mar 22 21:41:20 2002 --- src/proto/screen.pro Tue Feb 25 20:59:15 2003 *************** *** 19,25 **** int stl_connected __ARGS((win_T *wp)); int get_keymap_str __ARGS((win_T *wp, char_u *buf, int len)); void screen_putchar __ARGS((int c, int row, int col, int attr)); ! int screen_getchar __ARGS((int row, int col, int *attrp)); void screen_puts __ARGS((char_u *text, int row, int col, int attr)); void screen_stop_highlight __ARGS((void)); void reset_cterm_colors __ARGS((void)); --- 19,25 ---- int stl_connected __ARGS((win_T *wp)); int get_keymap_str __ARGS((win_T *wp, char_u *buf, int len)); void screen_putchar __ARGS((int c, int row, int col, int attr)); ! void screen_getbytes __ARGS((int row, int col, char_u *bytes, int *attrp)); void screen_puts __ARGS((char_u *text, int row, int col, int attr)); void screen_stop_highlight __ARGS((void)); void reset_cterm_colors __ARGS((void)); *** ../vim61.359/src/screen.c Wed Jan 29 10:14:44 2003 --- src/screen.c Tue Feb 25 20:57:42 2003 *************** *** 5117,5129 **** } /* ! * Get a single character directly from ScreenLines. * Also return its attribute in *attrp; - * For multi-byte chars only the first byte is obtained! */ ! int ! screen_getchar(row, col, attrp) int row, col; int *attrp; { unsigned off; --- 5128,5140 ---- } /* ! * Get a single character directly from ScreenLines into "bytes[]". * Also return its attribute in *attrp; */ ! void ! screen_getbytes(row, col, bytes, attrp) int row, col; + char_u *bytes; int *attrp; { unsigned off; *************** *** 5133,5141 **** { off = LineOffset[row] + col; *attrp = ScreenAttrs[off]; ! return ScreenLines[off]; } - return 0; } /* --- 5144,5168 ---- { off = LineOffset[row] + col; *attrp = ScreenAttrs[off]; ! bytes[0] = ScreenLines[off]; ! bytes[1] = NUL; ! ! #ifdef FEAT_MBYTE ! if (enc_utf8 && ScreenLinesUC[off] != 0) ! bytes[utfc_char2bytes(off, bytes)] = NUL; ! else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) ! { ! bytes[0] = ScreenLines[off]; ! bytes[1] = ScreenLines2[off]; ! bytes[2] = NUL; ! } ! else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) ! { ! bytes[1] = ScreenLines[off + 1]; ! bytes[2] = NUL; ! } ! #endif } } /* *** ../vim61.359/src/version.c Tue Feb 25 19:55:09 2003 --- src/version.c Tue Feb 25 21:05:25 2003 *************** *** 608,609 **** --- 612,615 ---- { /* Add new patch number below this line */ + /**/ + 360, /**/ -- TALL KNIGHT: When you have found the shrubbery, then you must cut down the mightiest tree in the forest ... with a herring. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///