Merge #9008 from janlazo/vim-8.0.1416

This commit is contained in:
Justin M. Keyes 2018-09-17 10:40:48 +02:00 committed by GitHub
commit 398b9fde85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 21 deletions

View File

@ -3664,17 +3664,18 @@ static linenr_T get_address(exarg_T *eap,
*/ */
if (lnum != MAXLNUM) if (lnum != MAXLNUM)
curwin->w_cursor.lnum = lnum; curwin->w_cursor.lnum = lnum;
/*
* Start a forward search at the end of the line. // Start a forward search at the end of the line (unless
* Start a backward search at the start of the line. // before the first line).
* This makes sure we never match in the current // Start a backward search at the start of the line.
* line, and can match anywhere in the // This makes sure we never match in the current
* next/previous line. // line, and can match anywhere in the
*/ // next/previous line.
if (c == '/') if (c == '/' && curwin->w_cursor.lnum > 0) {
curwin->w_cursor.col = MAXCOL; curwin->w_cursor.col = MAXCOL;
else } else {
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
}
searchcmdlen = 0; searchcmdlen = 0;
if (!do_search(NULL, c, cmd, 1L, if (!do_search(NULL, c, cmd, 1L,
SEARCH_HIS | SEARCH_MSG, NULL)) { SEARCH_HIS | SEARCH_MSG, NULL)) {

View File

@ -3999,18 +3999,15 @@ void goto_byte(long cnt)
/// Return 0 otherwise. /// Return 0 otherwise.
int inc(pos_T *lp) int inc(pos_T *lp)
{ {
char_u *p = ml_get_pos(lp); // when searching position may be set to end of a line
if (lp->col != MAXCOL) {
if (*p != NUL) { // still within line, move to next char (may be NUL) const char_u *const p = ml_get_pos(lp);
if (has_mbyte) { if (*p != NUL) { // still within line, move to next char (may be NUL)
int l = (*mb_ptr2len)(p); const int l = utfc_ptr2len(p);
lp->col += l; lp->col += l;
return (p[l] != NUL) ? 0 : 2; return ((p[l] != NUL) ? 0 : 2);
} }
lp->col++;
lp->coladd = 0;
return (p[1] != NUL) ? 0 : 2;
} }
if (lp->lnum != curbuf->b_ml.ml_line_count) { // there is a next line if (lp->lnum != curbuf->b_ml.ml_line_count) { // there is a next line
lp->col = 0; lp->col = 0;
@ -4035,20 +4032,32 @@ int incl(pos_T *lp)
int dec(pos_T *lp) int dec(pos_T *lp)
{ {
lp->coladd = 0; lp->coladd = 0;
if (lp->col > 0) { // still within line if (lp->col == MAXCOL) {
// past end of line
char_u *p = ml_get(lp->lnum);
lp->col = (colnr_T)STRLEN(p);
lp->col -= utf_head_off(p, p + lp->col);
return 0;
}
if (lp->col > 0) {
// still within line
lp->col--; lp->col--;
char_u *p = ml_get(lp->lnum); char_u *p = ml_get(lp->lnum);
lp->col -= utf_head_off(p, p + lp->col); lp->col -= utf_head_off(p, p + lp->col);
return 0; return 0;
} }
if (lp->lnum > 1) { // there is a prior line if (lp->lnum > 1) {
// there is a prior line
lp->lnum--; lp->lnum--;
char_u *p = ml_get(lp->lnum); char_u *p = ml_get(lp->lnum);
lp->col = (colnr_T)STRLEN(p); lp->col = (colnr_T)STRLEN(p);
lp->col -= utf_head_off(p, p + lp->col); lp->col -= utf_head_off(p, p + lp->col);
return 1; return 1;
} }
return -1; // at start of file
// at start of file
return -1;
} }
/// Same as dec(), but skip NUL at the end of non-empty lines. /// Same as dec(), but skip NUL at the end of non-empty lines.

View File

@ -1752,6 +1752,10 @@ del_lines (
int gchar_pos(pos_T *pos) int gchar_pos(pos_T *pos)
{ {
// When searching columns is sometimes put at the end of a line.
if (pos->col == MAXCOL) {
return NUL;
}
return utf_ptr2char(ml_get_pos(pos)); return utf_ptr2char(ml_get_pos(pos));
} }

View File

@ -480,3 +480,12 @@ func Test_look_behind()
call search(getline(".")) call search(getline("."))
bwipe! bwipe!
endfunc endfunc
func Test_search_sentence()
new
" this used to cause a crash
call assert_fails("/\\%')", 'E486')
call assert_fails("/", 'E486')
/\%'(
/
endfunc