To: vim-dev@vim.org Subject: Patch 6.0.196 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.196 Problem: When 'virtualedit' is set, 'selection' is "exclusive" and visually selecting part of a tab at the start of a line, "x" joins it with the previous line. Also, when the selection spans more than one line the whole tab is deleted. Solution: Take coladd into account when adjusting for 'selection' being "exclusive". Also expand a tab into spaces when deleting more than one line. Files: src/normal.c, src/ops.c *** ../vim60.195/src/normal.c Wed Feb 6 17:47:31 2002 --- src/normal.c Thu Feb 7 11:53:11 2002 *************** *** 5147,5156 **** /* In virtual mode when off the edge of a line and an operator * is pending (whew!) keep the cursor where it is. * Otherwise, send it to the end of the line. */ ! if (!virtual_active() || gchar_cursor() != NUL || ! cap->oap->op_type == OP_NOP) #endif ! curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (cursor_down((long)(cap->count1 - 1), cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); --- 5147,5156 ---- /* In virtual mode when off the edge of a line and an operator * is pending (whew!) keep the cursor where it is. * Otherwise, send it to the end of the line. */ ! if (!virtual_active() || gchar_cursor() != NUL ! || cap->oap->op_type == OP_NOP) #endif ! curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (cursor_down((long)(cap->count1 - 1), cap->oap->op_type == OP_NOP) == FAIL) clearopbeep(cap->oap); *************** *** 6563,6571 **** #ifdef FEAT_VISUAL pos_T tpos; #endif - #ifdef FEAT_VIRTUALEDIT - int coladd; - #endif int i; int flag = FALSE; --- 6563,6568 ---- *************** *** 6627,6636 **** curbuf->b_visual_end = curwin->w_cursor; curwin->w_cursor = curbuf->b_visual_start; curbuf->b_visual_start = VIsual; - - #ifdef FEAT_VIRTUALEDIT - coladd = tpos.coladd; - #endif } else { --- 6624,6629 ---- *************** *** 6638,6646 **** curwin->w_curswant = curbuf->b_visual_curswant; tpos = curbuf->b_visual_end; curwin->w_cursor = curbuf->b_visual_start; - #ifdef FEAT_VIRTUALEDIT - coladd = curbuf->b_visual_end.coladd; - #endif } VIsual_active = TRUE; --- 6631,6636 ---- *************** *** 6651,6659 **** check_cursor(); VIsual = curwin->w_cursor; curwin->w_cursor = tpos; - #ifdef FEAT_VIRTUALEDIT - curwin->w_cursor.coladd = coladd; - #endif check_cursor(); update_topline(); /* --- 6641,6646 ---- *************** *** 7425,7430 **** --- 7412,7422 ---- pp = &curwin->w_cursor; else pp = &VIsual; + #ifdef FEAT_VIRTUALEDIT + if (pp->coladd > 0) + --pp->coladd; + else + #endif if (pp->col > 0) --pp->col; else if (pp->lnum > 1) *** ../vim60.195/src/ops.c Tue Feb 5 21:56:42 2002 --- src/ops.c Thu Feb 7 12:18:11 2002 *************** *** 1621,1724 **** u_clearline(); /* "U" command not possible after "dd" */ } } ! else if (oap->line_count == 1) /* delete characters within one line */ { ! if (u_save_cursor() == FAIL) return FAIL; - /* if 'cpoptions' contains '$', display '$' at end of change */ - if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL - && oap->op_type == OP_CHANGE - && oap->end.lnum == curwin->w_cursor.lnum - #ifdef FEAT_VISUAL - && !oap->is_VIsual - #endif - ) - display_dollar(oap->end.col - !oap->inclusive); - n = oap->end.col - oap->start.col + 1 - !oap->inclusive; #ifdef FEAT_VIRTUALEDIT - if (virtual_active()) { ! /* fix up things for virtualedit-delete: ! * make sure the coladds are in the right order, and ! * break the tabs which are going to get in our way ! */ ! char_u *curline = ml_get_curline(); ! int oldcol = getviscol(); ! int len; ! int endcol; ! if (oap->start.col == oap->end.col ! && oap->end.coladd < oap->start.coladd) { ! colnr_T tmp = oap->start.coladd; ! oap->start.coladd = oap->end.coladd; ! oap->end.coladd = tmp; ! ! curwin->w_cursor.coladd = oap->start.coladd; ! } ! ! if (curline[oap->start.col] == '\t') ! { ! endcol = getviscol2(oap->end.col, oap->end.coladd); coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); ! oap->start.col = curwin->w_cursor.col; ! oap->start.coladd = 0; ! coladvance(endcol); ! oap->end.col = curwin->w_cursor.col; ! oap->end.coladd = curwin->w_cursor.coladd; ! coladvance(oldcol); ! curline = ml_get_curline(); } ! if (curline[oap->end.col] == '\t') { coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); ! oap->end.col = curwin->w_cursor.col; ! oap->end.coladd = 0; ! coladvance(oldcol); ! curline = ml_get_curline(); } n = oap->end.col - oap->start.col + 1 - !oap->inclusive; - len = (int)STRLEN(curline); ! if (oap->end.coladd != 0 && (int)oap->end.col >= len - 1 ! && !(oap->start.coladd && (int)oap->end.col >= len - 1)) ! n++; ! /* Delete at least one character (e.g, when on a control char). */ ! if (n == 0 && oap->start.coladd != oap->end.coladd) ! n = 1; ! ! /* When deleted a char in the line, reset coladd. */ ! if (gchar_cursor() != NUL) ! curwin->w_cursor.coladd = 0; ! } #endif ! (void)del_bytes((long)n, restart_edit == NUL); ! } ! else /* delete characters between lines */ ! { ! if (u_save_cursor() == FAIL) /* save first line for undo */ ! return FAIL; ! truncate_line(TRUE); /* delete from cursor to end of line */ ! ! oap->start = curwin->w_cursor; /* remember curwin->w_cursor */ ! ++curwin->w_cursor.lnum; ! /* includes save for undo */ ! del_lines((long)(oap->line_count - 2), TRUE); ! if (u_save_cursor() == FAIL) /* save last line for undo */ ! return FAIL; ! u_clearline(); /* "U" should not be possible now */ ! /* delete from start of line until op_end */ ! curwin->w_cursor.col = 0; ! (void)del_bytes((long)(oap->end.col + 1 - !oap->inclusive), restart_edit == NUL); ! curwin->w_cursor = oap->start; /* restore curwin->w_cursor */ ! (void)do_join(FALSE); } msgmore(curbuf->b_ml.ml_line_count - old_lcount); --- 1621,1720 ---- u_clearline(); /* "U" command not possible after "dd" */ } } ! else { ! if (u_save_cursor() == FAIL) /* save first line for undo */ return FAIL; #ifdef FEAT_VIRTUALEDIT if (virtual_active()) { ! int endcol = 0; ! /* For virtualedit: break the tabs that are partly included. */ ! if (gchar_pos(&oap->start) == '\t') { ! if (oap->line_count == 1) ! endcol = getviscol2(oap->end.col, oap->end.coladd); coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); ! oap->start = curwin->w_cursor; ! if (oap->line_count == 1) ! { ! coladvance(endcol); ! oap->end.col = curwin->w_cursor.col; ! oap->end.coladd = curwin->w_cursor.coladd; ! curwin->w_cursor = oap->start; ! } } ! if (gchar_pos(&oap->end) == '\t') { + curwin->w_cursor = oap->end; coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); ! oap->end = curwin->w_cursor; ! curwin->w_cursor = oap->start; } + } + #endif + + if (oap->line_count == 1) /* delete characters within one line */ + { + /* if 'cpoptions' contains '$', display '$' at end of change */ + if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL + && oap->op_type == OP_CHANGE + && oap->end.lnum == curwin->w_cursor.lnum + #ifdef FEAT_VISUAL + && !oap->is_VIsual + #endif + ) + display_dollar(oap->end.col - !oap->inclusive); n = oap->end.col - oap->start.col + 1 - !oap->inclusive; ! #ifdef FEAT_VIRTUALEDIT ! if (virtual_active()) ! { ! /* fix up things for virtualedit-delete: ! * break the tabs which are going to get in our way ! */ ! char_u *curline = ml_get_curline(); ! int len = (int)STRLEN(curline); ! ! if (oap->end.coladd != 0 ! && (int)oap->end.col >= len - 1 ! && !(oap->start.coladd && (int)oap->end.col >= len - 1)) ! n++; ! /* Delete at least one char (e.g, when on a control char). */ ! if (n == 0 && oap->start.coladd != oap->end.coladd) ! n = 1; ! ! /* When deleted a char in the line, reset coladd. */ ! if (gchar_cursor() != NUL) ! curwin->w_cursor.coladd = 0; ! } #endif ! (void)del_bytes((long)n, restart_edit == NUL); ! } ! else /* delete characters between lines */ ! { ! truncate_line(TRUE); /* delete from cursor to end of line */ ! oap->start = curwin->w_cursor; /* remember curwin->w_cursor */ ! ++curwin->w_cursor.lnum; ! /* includes save for undo */ ! del_lines((long)(oap->line_count - 2), TRUE); ! ! if (u_save_cursor() == FAIL) /* save last line for undo */ ! return FAIL; ! u_clearline(); /* "U" not possible now */ ! /* delete from start of line until op_end */ ! curwin->w_cursor.col = 0; ! (void)del_bytes((long)(oap->end.col + 1 - !oap->inclusive), restart_edit == NUL); ! curwin->w_cursor = oap->start; /* restore curwin->w_cursor */ ! (void)do_join(FALSE); ! } } msgmore(curbuf->b_ml.ml_line_count - old_lcount); *** ../vim60.195/src/version.c Thu Feb 7 11:37:45 2002 --- src/version.c Thu Feb 7 12:22:19 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 196, /**/ -- hundred-and-one symptoms of being an internet addict: 261. You find diskettes in your pockets when doing laundry. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///