aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-07-17 10:55:18 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-07-17 11:04:55 +0800
commite83949f96c59de706a175a017e6a080b838118d1 (patch)
tree547c36e88506a251bab9c40472958be345ad09a4
parentccdbab7810bd40a44a0a502d478b0d06073388e9 (diff)
downloadrneovim-e83949f96c59de706a175a017e6a080b838118d1.tar.gz
rneovim-e83949f96c59de706a175a017e6a080b838118d1.tar.bz2
rneovim-e83949f96c59de706a175a017e6a080b838118d1.zip
vim-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 vim/vim#10938) https://github.com/vim/vim/commit/753aead960f163d0d3f8ce523ea523f2e0cec06d Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/regexp.c20
-rw-r--r--test/old/testdir/test_regexp_latin.vim6
2 files changed, 15 insertions, 11 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 22859a1e54..bd9fbf00be 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -6256,13 +6256,12 @@ static bool regmatch(uint8_t *scan, const proftime_T *tm, int *timed_out)
case RE_VCOL: {
win_T *wp = rex.reg_win == NULL ? curwin : rex.reg_win;
- linenr_T lnum = rex.reg_firstlnum + rex.lnum;
- int vcol = 0;
-
- if (lnum >= 0 && lnum <= wp->w_buffer->b_ml.ml_line_count) {
- vcol = win_linetabsize(wp, lnum, (char *)rex.line,
- (colnr_T)(rex.input - rex.line));
+ linenr_T lnum = REG_MULTI ? rex.reg_firstlnum + rex.lnum : 1;
+ if (REG_MULTI && (lnum <= 0 || lnum > wp->w_buffer->b_ml.ml_line_count)) {
+ lnum = 1;
}
+ int vcol = win_linetabsize(wp, lnum, (char *)rex.line,
+ (colnr_T)(rex.input - rex.line));
if (!re_num_cmp((uint32_t)vcol + 1, scan)) {
status = RA_NOMATCH;
}
@@ -15105,12 +15104,11 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
result = col > t->state->val * ts;
}
if (!result) {
- linenr_T lnum = rex.reg_firstlnum + rex.lnum;
- int vcol = 0;
-
- if (lnum >= 0 && lnum <= wp->w_buffer->b_ml.ml_line_count) {
- vcol = win_linetabsize(wp, lnum, (char *)rex.line, col);
+ linenr_T lnum = REG_MULTI ? rex.reg_firstlnum + rex.lnum : 1;
+ if (REG_MULTI && (lnum <= 0 || lnum > wp->w_buffer->b_ml.ml_line_count)) {
+ lnum = 1;
}
+ int vcol = win_linetabsize(wp, lnum, (char *)rex.line, col);
assert(t->state->val >= 0);
result = nfa_re_num_cmp((uintmax_t)t->state->val, op, (uintmax_t)vcol + 1);
}
diff --git a/test/old/testdir/test_regexp_latin.vim b/test/old/testdir/test_regexp_latin.vim
index 754fa8c868..ac46d0b17b 100644
--- a/test/old/testdir/test_regexp_latin.vim
+++ b/test/old/testdir/test_regexp_latin.vim
@@ -1151,7 +1151,13 @@ endfunc
" enddef
func Test_compare_column_matchstr()
+ " do some search in text to set the line number, it should be ignored in
+ " matchstr().
enew
+ call setline(1, ['one', 'two', 'three'])
+ :3
+ :/ee
+ bwipe!
set re=1
call assert_equal('aaa', matchstr('aaaaaaaaaaaaaaaaaaaa', '.*\%<5v'))
set re=2