From d677ae5f6461dcd78f08caec2c4fa72e6e275137 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 23 Aug 2018 04:43:44 -0400 Subject: vim-patch:8.0.1041: bogus characters when indenting during visual-block append Problem: Bogus characters appear when indenting kicks in while doing a visual-block append. Solution: Recompute when indenting is done. (Christian Brabandt) https://github.com/vim/vim/commit/e2e69e48134cbfdedea7802810932f8592705024 --- src/nvim/ops.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ff02d82ff3..f3661b2045 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2014,6 +2014,7 @@ void op_insert(oparg_T *oap, long count1) { long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; + colnr_T ind_pre, ind_post; struct block_def bd; int i; pos_T t1; @@ -2044,7 +2045,10 @@ void op_insert(oparg_T *oap, long count1) } // 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) firstline += bd.textlen; pre_textlen = (long)STRLEN(firstline); @@ -2091,6 +2095,14 @@ void op_insert(oparg_T *oap, long count1) oap->start = curbuf->b_op_start_orig; } + // 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; + } + /* If user has moved off this line, we don't know what to do, so do * nothing. * Also don't repeat the insert when Insert mode ended with CTRL-C. */ @@ -2216,7 +2228,7 @@ int op_change(oparg_T *oap) } firstline = ml_get(oap->start.lnum); pre_textlen = (long)STRLEN(firstline); - pre_indent = (long)(skipwhite(firstline) - firstline); + pre_indent = (long)getwhitecols(firstline); bd.textcol = curwin->w_cursor.col; } @@ -2237,7 +2249,7 @@ int op_change(oparg_T *oap) // the indent, exclude that indent change from the inserted text. firstline = ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { - long new_indent = (long)(skipwhite(firstline) - firstline); + long new_indent = (long)getwhitecols(firstline); pre_textlen += new_indent - pre_indent; bd.textcol += (colnr_T)(new_indent - pre_indent); @@ -4122,8 +4134,7 @@ format_lines ( mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, (long)-next_leader_len); } else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */ - char_u *p = get_cursor_line_ptr(); - int indent = (int)(skipwhite(p) - p); + int indent = (int)getwhitecols_curline(); if (indent > 0) { (void)del_bytes(indent, FALSE, FALSE); -- cgit From fb68c97ce8950fdf598a0b7ff9be7cc3fa624f2e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 23 Aug 2018 09:57:07 -0400 Subject: vim-patch:8.0.1043: warning for uninitialized variable Problem: Warning for uninitialized variable. (John Marriott) Solution: Move code to check indent inside "if". https://github.com/vim/vim/commit/4ec86ddd77a89766e42bd0a6cfcf10af4c3d03b2 --- src/nvim/ops.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f3661b2045..4d8403bee8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2014,7 +2014,7 @@ void op_insert(oparg_T *oap, long count1) { long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; - colnr_T ind_pre, ind_post; + colnr_T ind_pre; struct block_def bd; int i; pos_T t1; @@ -2095,14 +2095,6 @@ void op_insert(oparg_T *oap, long count1) oap->start = curbuf->b_op_start_orig; } - // 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; - } - /* If user has moved off this line, we don't know what to do, so do * nothing. * Also don't repeat the insert when Insert mode ended with CTRL-C. */ @@ -2112,6 +2104,14 @@ void op_insert(oparg_T *oap, long count1) if (oap->motion_type == kMTBlockWise) { struct block_def bd2; + // if indent kicked in, the firstline might have changed + // but only do that, if the indent actually increased + const colnr_T 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; + } + /* The user may have moved the cursor before inserting something, try * to adjust the block for that. */ if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) { -- cgit From 27fbffeb4f56a76a24a8d8b348caf6f733f2fc4d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 23 Aug 2018 09:59:41 -0400 Subject: vim-patch:8.0.1044: warning for uninitialized variable Problem: Warning for uninitialized variable. (John Marriott) Solution: Initialize ind_pre. https://github.com/vim/vim/commit/2254a8ad0cb596a0a0863b1af92353f018c0b355 --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4d8403bee8..d6f60f33da 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2014,7 +2014,7 @@ void op_insert(oparg_T *oap, long count1) { long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; - colnr_T ind_pre; + colnr_T ind_pre = 0; struct block_def bd; int i; pos_T t1; -- cgit From 6c8851be4e5ce8cbd6f224451fae8a0adc292bf6 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 23 Aug 2018 04:13:29 -0400 Subject: lint --- src/nvim/ops.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d6f60f33da..9e837c1e12 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2049,8 +2049,9 @@ void op_insert(oparg_T *oap, long count1) ind_pre = (colnr_T)getwhitecols_curline(); firstline = ml_get(oap->start.lnum) + bd.textcol; - if (oap->op_type == OP_APPEND) + if (oap->op_type == OP_APPEND) { firstline += bd.textlen; + } pre_textlen = (long)STRLEN(firstline); } @@ -4132,8 +4133,8 @@ format_lines ( if (next_leader_len > 0) { (void)del_bytes(next_leader_len, false, false); mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, - (long)-next_leader_len); - } else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */ + (long)-next_leader_len); + } else if (second_indent > 0) { // the "leader" for FO_Q_SECOND int indent = (int)getwhitecols_curline(); if (indent > 0) { -- cgit