To: vim-dev@vim.org Subject: Patch 5.6.050 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.050 Problem: Replacing is wrong when replacing a single-byte char with double-byte char or the other way around. Solution: Shift the text after the character when it is replaced. (Yasuhiro Matsumoto) Files: src/normal.c, src/misc1.c *** ../vim-5.6.49/src/normal.c Thu Mar 23 17:46:04 2000 --- src/normal.c Sun Apr 2 12:30:31 2000 *************** *** 4522,4531 **** #ifdef MULTI_BYTE if (is_dbcs) { if (trailbyte != NUL) ! ptr[curwin->w_cursor.col++] = trailbyte; else if (IsLeadByte(prechar)) ! (void)del_chars((long)1, TRUE); } #endif } --- 4522,4544 ---- #ifdef MULTI_BYTE if (is_dbcs) { + /* Handle three situations: + * 1. replace double-byte with double-byte: set trailbyte. + * 2. replace single-byte with double-byte: insert trailbyte. + * 3. replace double-byte with single-bute: delete char. + */ if (trailbyte != NUL) ! { ! if (IsLeadByte(prechar)) ! ptr[curwin->w_cursor.col] = trailbyte; ! else ! (void)ins_char(trailbyte); ! } else if (IsLeadByte(prechar)) ! { ! (void)del_char(TRUE); ! ++curwin->w_cursor.col; ! } } #endif } *** ../vim-5.6.49/src/misc1.c Fri Mar 31 14:23:12 2000 --- src/misc1.c Sun Apr 2 12:55:38 2000 *************** *** 1354,1359 **** --- 1354,1363 ---- extra = 1; else extra = 0; + #ifdef MULTI_BYTE + if (is_dbcs && State == REPLACE && IsLeadByte(c)) + extra = 1; + #endif /* * A character has to be put on the replace stack if there is a *************** *** 1410,1416 **** curwin->w_p_list = old_list; } ! newp = alloc_check((unsigned)(oldlen + extra)); if (newp == NULL) return; if (col > 0) --- 1414,1431 ---- curwin->w_p_list = old_list; } ! #ifdef MULTI_BYTE ! if (State == REPLACE && is_dbcs) ! { ! /* For multi-byte add one byte when new char is multi-byte, subtract ! * one byte when old char was multi-byte. */ ! newp = alloc_check((unsigned)(oldlen + extra ! + (IsLeadByte(c) ? 1 : 0) ! - (IsLeadByte(oldp[col]) ? 1 : 0))); ! } ! else ! #endif ! newp = alloc_check((unsigned)(oldlen + extra)); if (newp == NULL) return; if (col > 0) *************** *** 1422,1438 **** mch_memmove(p + 1, oldp + i, (size_t)(oldlen - i)); } else ! mch_memmove(p + extra, oldp + col, (size_t)(oldlen - col)); ! #ifdef MULTI_BYTE ! /* ! * We define that "[]" is a multi-byte character. For example, if ! * replace(R) is done over "a[]" with "[]". Finally, "[]]" is ! * constructed, but the following line replaces "[]]" with "[] ". ! */ ! if (is_dbcs && State == REPLACE && IsLeadByte(*p) && p[1] != NUL) ! p[1] = ' '; #endif *p = c; ml_replace(lnum, newp, FALSE); --- 1437,1452 ---- mch_memmove(p + 1, oldp + i, (size_t)(oldlen - i)); } else ! { #ifdef MULTI_BYTE ! /* if oldp have multi-byte, don't move old trail byte */ ! if (is_dbcs && State == REPLACE && IsLeadByte(oldp[col])) ! mch_memmove(p + extra, oldp + col + 1, (size_t)(oldlen - col - 1)); ! else #endif + mch_memmove(p + extra, oldp + col, (size_t)(oldlen - col)); + } + *p = c; ml_replace(lnum, newp, FALSE); *** ../vim-5.6.49/src/version.c Sun Apr 2 12:06:32 2000 --- src/version.c Sun Apr 2 13:01:09 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 50, /**/ -- Florida: A special law prohibits unmarried women from parachuting on Sunday or she shall risk arrest, fine, and/or jailing. [real standing law in Florida, United States of America] /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/