To: vim_dev@googlegroups.com Subject: Patch 8.2.3687 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3687 Problem: Blockwise insert does not handle autoindent properly when tab is inserted. Solution: Adjust text column for indent before computing column. (closes #9229) Files: src/ops.c, src/testdir/test_blockedit.vim *** ../vim-8.2.3686/src/ops.c 2021-11-27 13:28:19.032531494 +0000 --- src/ops.c 2021-11-27 22:39:09.677958943 +0000 *************** *** 1456,1462 **** { long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; ! colnr_T ind_pre = 0, ind_post; struct block_def bd; int i; pos_T t1; --- 1456,1463 ---- { long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; ! colnr_T ind_pre_col = 0, ind_post_col; ! int ind_pre_vcol = 0, ind_post_vcol = 0; struct block_def bd; int i; pos_T t1; *************** *** 1497,1503 **** // Get the info about the block before entering the text block_prep(oap, &bd, oap->start.lnum, TRUE); // Get indent information ! ind_pre = (colnr_T)getwhitecols_curline(); firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) --- 1498,1505 ---- // Get the info about the block before entering the text block_prep(oap, &bd, oap->start.lnum, TRUE); // Get indent information ! ind_pre_col = (colnr_T)getwhitecols_curline(); ! ind_pre_vcol = get_indent(); firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) *************** *** 1563,1573 **** // If indent kicked in, the firstline might have changed // but only do that, if the indent actually increased. ! ind_post = (colnr_T)getwhitecols_curline(); ! if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) { ! bd.textcol += ind_post - ind_pre; ! bd.start_vcol += ind_post - ind_pre; did_indent = TRUE; } --- 1565,1576 ---- // If indent kicked in, the firstline might have changed // but only do that, if the indent actually increased. ! ind_post_col = (colnr_T)getwhitecols_curline(); ! if (curbuf->b_op_start.col > ind_pre_col && ind_post_col > ind_pre_col) { ! bd.textcol += ind_post_col - ind_pre_col; ! ind_post_vcol = get_indent(); ! bd.start_vcol += ind_post_vcol - ind_pre_vcol; did_indent = TRUE; } *************** *** 1612,1623 **** } } ! /* ! * Spaces and tabs in the indent may have changed to other spaces and ! * tabs. Get the starting column again and correct the length. ! * Don't do this when "$" used, end-of-line will have changed. ! */ block_prep(oap, &bd2, oap->start.lnum, TRUE); if (!bd.is_MAX || bd2.textlen < bd.textlen) { if (oap->op_type == OP_APPEND) --- 1615,1642 ---- } } ! // Spaces and tabs in the indent may have changed to other spaces and ! // tabs. Get the starting column again and correct the length. ! // Don't do this when "$" used, end-of-line will have changed. ! // ! // if indent was added and the inserted text was after the indent, ! // correct the selection for the new indent. ! if (did_indent && bd.textcol - ind_post_col > 0) ! { ! oap->start.col += ind_post_col - ind_pre_col; ! oap->start_vcol += ind_post_vcol - ind_pre_vcol; ! oap->end.col += ind_post_col - ind_pre_col; ! oap->end_vcol += ind_post_vcol - ind_pre_vcol; ! } block_prep(oap, &bd2, oap->start.lnum, TRUE); + if (did_indent && bd.textcol - ind_post_col > 0) + { + // undo for where "oap" is used below + oap->start.col -= ind_post_col - ind_pre_col; + oap->start_vcol -= ind_post_vcol - ind_pre_vcol; + oap->end.col -= ind_post_col - ind_pre_col; + oap->end_vcol -= ind_post_vcol - ind_pre_vcol; + } if (!bd.is_MAX || bd2.textlen < bd.textlen) { if (oap->op_type == OP_APPEND) *************** *** 1627,1636 **** --bd2.textlen; } bd.textcol = bd2.textcol; - if (did_indent && bd.textcol > ind_pre) - // If the insert was in the indent then include the indent - // change in the new text, otherwise don't. - bd.textcol += ind_post - ind_pre; bd.textlen = bd2.textlen; } --- 1646,1651 ---- *** ../vim-8.2.3686/src/testdir/test_blockedit.vim 2021-11-27 13:28:19.032531494 +0000 --- src/testdir/test_blockedit.vim 2021-11-27 22:46:46.688763980 +0000 *************** *** 37,42 **** --- 37,67 ---- END call assert_equal(expected, getline(1, 5)) + " insert on the next column should do exactly the same + :%dele + call setline(1, lines) + exe "norm! 2Gf)l\2jI: asdf\" + call assert_equal(expected, getline(1, 5)) + + :%dele + call setline(1, lines) + setlocal sw=8 noet + exe "norm! 2Gf)\2jA: asdf\" + let expected =<< trim END + var d = { + a: (): asdf => 0, + b: (): asdf => 0, + c: (): asdf => 0, + } + END + call assert_equal(expected, getline(1, 5)) + + " insert on the next column should do exactly the same + :%dele + call setline(1, lines) + exe "norm! 2Gf)l\2jI: asdf\" + call assert_equal(expected, getline(1, 5)) + filetype off bwipe! endfunc *** ../vim-8.2.3686/src/version.c 2021-11-27 17:21:54.085161469 +0000 --- src/version.c 2021-11-27 18:49:07.133032249 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3687, /**/ -- Corn oil comes from corn and olive oil comes from olives, so where does baby oil come from? /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///