To: vim-dev@vim.org Subject: Patch 6.1.079 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.079 Problem: When using "s" in Visual block mode with 'virtualedit' set, when the selected block is after the end of some lines the wrong text is inserted and some lines are skipped. (Servatius Brandt) Solution: Insert the right text and extend short lines. Files: src/ops.c *** ../vim61.078/src/ops.c Thu May 16 21:50:46 2002 --- src/ops.c Thu May 16 20:01:35 2002 *************** *** 1570,1576 **** --- 1570,1581 ---- /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ if (lnum == curwin->w_cursor.lnum) + { curwin->w_cursor.col = bd.textcol + bd.startspaces; + # ifdef FEAT_VIRTUALEDIT + curwin->w_cursor.coladd = 0; + # endif + } /* n == number of chars deleted * If we delete a TAB, it may be replaced by several characters. *************** *** 2337,2345 **** /* skip blank lines too */ if (oap->block_mode) { ! firstline = ml_get(oap->start.lnum); ! pre_textlen = (long)STRLEN(firstline); ! block_prep(oap, &bd, oap->start.lnum, TRUE); } #endif --- 2342,2355 ---- /* skip blank lines too */ if (oap->block_mode) { ! # ifdef FEAT_VIRTUALEDIT ! /* Add spaces before getting the current line length. */ ! if (virtual_op && (curwin->w_cursor.coladd > 0 ! || gchar_cursor() == NUL)) ! coladvance_force(getviscol()); ! # endif ! pre_textlen = (long)STRLEN(ml_get(oap->start.lnum)); ! bd.textcol = curwin->w_cursor.col; } #endif *************** *** 2367,2392 **** if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) { STRNCPY(ins_text, firstline + bd.textcol, ins_len); ! *(ins_text + ins_len) = NUL; for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { block_prep(oap, &bd, linenr, TRUE); ! if (!bd.is_short) { oldp = ml_get(linenr); newp = alloc_check((unsigned)(STRLEN(oldp) + ins_len + 1)); if (newp == NULL) continue; /* copy up to block start */ mch_memmove(newp, oldp, (size_t)bd.textcol); ! for (offset = 0; offset < ins_len; offset++) ! *(newp + bd.textcol + offset) = *(ins_text ! + offset); oldp += bd.textcol; ! mch_memmove(newp + bd.textcol + offset, oldp, ! STRLEN(oldp) + 1); ml_replace(linenr, newp, FALSE); } } --- 2377,2424 ---- if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) { STRNCPY(ins_text, firstline + bd.textcol, ins_len); ! ins_text[ins_len] = NUL; for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { block_prep(oap, &bd, linenr, TRUE); ! if (!bd.is_short || virtual_op) { + # ifdef FEAT_VIRTUALEDIT + pos_T vpos; + + /* If the block starts in virtual space, count the + * initial coladd offset as part of "startspaces" */ + if (bd.is_short) + { + linenr_T lnum = curwin->w_cursor.lnum; + + curwin->w_cursor.lnum = linenr; + (void)getvpos(&vpos, oap->start_vcol); + curwin->w_cursor.lnum = lnum; + } + else + vpos.coladd = 0; + # endif oldp = ml_get(linenr); newp = alloc_check((unsigned)(STRLEN(oldp) + # ifdef FEAT_VIRTUALEDIT + + vpos.coladd + # endif + ins_len + 1)); if (newp == NULL) continue; /* copy up to block start */ mch_memmove(newp, oldp, (size_t)bd.textcol); ! offset = bd.textcol; ! # ifdef FEAT_VIRTUALEDIT ! copy_spaces(newp + offset, (size_t)vpos.coladd); ! offset += vpos.coladd; ! # endif ! mch_memmove(newp + offset, ins_text, ins_len); ! offset += ins_len; oldp += bd.textcol; ! mch_memmove(newp + offset, oldp, STRLEN(oldp) + 1); ml_replace(linenr, newp, FALSE); } } *** ../vim61.078/src/version.c Sun May 19 21:29:28 2002 --- src/version.c Sun May 19 21:25:24 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 79, /**/ -- hundred-and-one symptoms of being an internet addict: 34. You laugh at people with 14400 baud modems. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///