# HG changeset patch # User Bram Moolenaar # Date 1662636603 -7200 # Node ID d58331e0f14a16d6eff43deecc0580adafaafcd5 # Parent a85a8accd27331368d5cc5a4dc0d9a2916cdccf7 patch 9.0.0414: matchstr() still does not match column offset Commit: https://github.com/vim/vim/commit/753aead960f163d0d3f8ce523ea523f2e0cec06d Author: Bram Moolenaar Date: Thu Sep 8 12:17:06 2022 +0100 patch 9.0.0414: matchstr() still does not match column offset Problem: matchstr() still does not match column offset when done after a text search. Solution: Only use the line number for a multi-line search. Fix the test. (closes #10938) diff --git a/src/regexp_bt.c b/src/regexp_bt.c --- a/src/regexp_bt.c +++ b/src/regexp_bt.c @@ -3441,11 +3441,13 @@ regmatch( case RE_VCOL: { win_T *wp = rex.reg_win == NULL ? curwin : rex.reg_win; - linenr_T lnum = rex.reg_firstlnum + rex.lnum; - long_u vcol = 0; - - if (lnum >= 0 && lnum <= wp->w_buffer->b_ml.ml_line_count) - vcol = (long_u)win_linetabsize(wp, lnum, rex.line, + linenr_T lnum = REG_MULTI ? rex.reg_firstlnum + rex.lnum : 1; + long_u vcol; + + if (REG_MULTI && (lnum <= 0 + || lnum > wp->w_buffer->b_ml.ml_line_count)) + lnum = 1; + vcol = (long_u)win_linetabsize(wp, lnum, rex.line, (colnr_T)(rex.input - rex.line)); if (!re_num_cmp(vcol + 1, scan)) status = RA_NOMATCH; diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c --- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -6775,12 +6775,14 @@ nfa_regmatch( } if (!result) { - linenr_T lnum = rex.reg_firstlnum + rex.lnum; - long_u vcol = 0; - - if (lnum >= 0 - && lnum <= wp->w_buffer->b_ml.ml_line_count) - vcol = (long_u)win_linetabsize(wp, lnum, + linenr_T lnum = REG_MULTI + ? rex.reg_firstlnum + rex.lnum : 1; + long_u vcol; + + if (REG_MULTI && (lnum <= 0 + || lnum > wp->w_buffer->b_ml.ml_line_count)) + lnum = 1; + vcol = (long_u)win_linetabsize(wp, lnum, rex.line, col); result = nfa_re_num_cmp(t->state->val, op, vcol + 1); } diff --git a/src/testdir/test_regexp_latin.vim b/src/testdir/test_regexp_latin.vim --- a/src/testdir/test_regexp_latin.vim +++ b/src/testdir/test_regexp_latin.vim @@ -1145,7 +1145,13 @@ def Test_compare_columns() enddef def Test_compare_column_matchstr() + # do some search in text to set the line number, it should be ignored in + # matchstr(). enew + setline(1, ['one', 'two', 'three']) + :3 + :/ee + bwipe! set re=1 call assert_equal('aaa', matchstr('aaaaaaaaaaaaaaaaaaaa', '.*\%<5v')) set re=2 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 414, +/**/ 413, /**/ 412,