forked from aniani/vim
patch 8.1.1700: listener callback called for the wrong buffer
Problem: Listener callback called for the wrong buffer. Solution: Invoke listeners before calling ml_append_int().
This commit is contained in:
132
src/memline.c
132
src/memline.c
@@ -243,7 +243,6 @@ static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf);
|
|||||||
static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf);
|
static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf);
|
||||||
static time_t swapfile_info(char_u *);
|
static time_t swapfile_info(char_u *);
|
||||||
static int recov_file_names(char_u **, char_u *, int prepend_dot);
|
static int recov_file_names(char_u **, char_u *, int prepend_dot);
|
||||||
static int ml_append_int(buf_T *, linenr_T, char_u *, colnr_T, int, int);
|
|
||||||
static int ml_delete_int(buf_T *, linenr_T, int);
|
static int ml_delete_int(buf_T *, linenr_T, int);
|
||||||
static char_u *findswapname(buf_T *, char_u **, char_u *);
|
static char_u *findswapname(buf_T *, char_u **, char_u *);
|
||||||
static void ml_flush_line(buf_T *);
|
static void ml_flush_line(buf_T *);
|
||||||
@@ -2744,56 +2743,6 @@ add_text_props_for_append(
|
|||||||
*tofree = new_line;
|
*tofree = new_line;
|
||||||
*len = new_len;
|
*len = new_len;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Append a line after lnum (may be 0 to insert a line in front of the file).
|
|
||||||
* "line" does not need to be allocated, but can't be another line in a
|
|
||||||
* buffer, unlocking may make it invalid.
|
|
||||||
*
|
|
||||||
* newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
|
|
||||||
* will be set for recovery
|
|
||||||
* Check: The caller of this function should probably also call
|
|
||||||
* appended_lines().
|
|
||||||
*
|
|
||||||
* return FAIL for failure, OK otherwise
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
ml_append(
|
|
||||||
linenr_T lnum, /* append after this line (can be 0) */
|
|
||||||
char_u *line, /* text of the new line */
|
|
||||||
colnr_T len, /* length of new line, including NUL, or 0 */
|
|
||||||
int newfile) /* flag, see above */
|
|
||||||
{
|
|
||||||
/* When starting up, we might still need to create the memfile */
|
|
||||||
if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
if (curbuf->b_ml.ml_line_lnum != 0)
|
|
||||||
ml_flush_line(curbuf);
|
|
||||||
return ml_append_int(curbuf, lnum, line, len, newfile, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(FEAT_SPELL) || defined(FEAT_QUICKFIX) || defined(PROTO)
|
|
||||||
/*
|
|
||||||
* Like ml_append() but for an arbitrary buffer. The buffer must already have
|
|
||||||
* a memline.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
ml_append_buf(
|
|
||||||
buf_T *buf,
|
|
||||||
linenr_T lnum, /* append after this line (can be 0) */
|
|
||||||
char_u *line, /* text of the new line */
|
|
||||||
colnr_T len, /* length of new line, including NUL, or 0 */
|
|
||||||
int newfile) /* flag, see above */
|
|
||||||
{
|
|
||||||
if (buf->b_ml.ml_mfp == NULL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
if (buf->b_ml.ml_line_lnum != 0)
|
|
||||||
ml_flush_line(buf);
|
|
||||||
return ml_append_int(buf, lnum, line, len, newfile, FALSE);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -2834,14 +2783,6 @@ ml_append_int(
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
len = (colnr_T)STRLEN(line) + 1; // space needed for the text
|
len = (colnr_T)STRLEN(line) + 1; // space needed for the text
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
|
||||||
// When inserting above recorded changes: flush the changes before changing
|
|
||||||
// the text. Then flush the cached line, it may become invalid.
|
|
||||||
may_invoke_listeners(buf, lnum + 1, lnum + 1, 1);
|
|
||||||
if (curbuf->b_ml.ml_line_lnum != 0)
|
|
||||||
ml_flush_line(curbuf);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
if (curbuf->b_has_textprop && lnum > 0)
|
if (curbuf->b_has_textprop && lnum > 0)
|
||||||
// Add text properties that continue from the previous line.
|
// Add text properties that continue from the previous line.
|
||||||
@@ -3325,6 +3266,79 @@ theend:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flush any pending change and call ml_append_int()
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
ml_append_flush(
|
||||||
|
buf_T *buf,
|
||||||
|
linenr_T lnum, // append after this line (can be 0)
|
||||||
|
char_u *line, // text of the new line
|
||||||
|
colnr_T len, // length of line, including NUL, or 0
|
||||||
|
int newfile) // flag, see above
|
||||||
|
{
|
||||||
|
if (lnum > buf->b_ml.ml_line_count)
|
||||||
|
return FAIL; // lnum out of range
|
||||||
|
|
||||||
|
if (buf->b_ml.ml_line_lnum != 0)
|
||||||
|
// This may also invoke ml_append_int().
|
||||||
|
ml_flush_line(buf);
|
||||||
|
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
// When inserting above recorded changes: flush the changes before changing
|
||||||
|
// the text. Then flush the cached line, it may become invalid.
|
||||||
|
may_invoke_listeners(buf, lnum + 1, lnum + 1, 1);
|
||||||
|
if (buf->b_ml.ml_line_lnum != 0)
|
||||||
|
ml_flush_line(buf);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ml_append_int(buf, lnum, line, len, newfile, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append a line after lnum (may be 0 to insert a line in front of the file).
|
||||||
|
* "line" does not need to be allocated, but can't be another line in a
|
||||||
|
* buffer, unlocking may make it invalid.
|
||||||
|
*
|
||||||
|
* newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
|
||||||
|
* will be set for recovery
|
||||||
|
* Check: The caller of this function should probably also call
|
||||||
|
* appended_lines().
|
||||||
|
*
|
||||||
|
* return FAIL for failure, OK otherwise
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ml_append(
|
||||||
|
linenr_T lnum, /* append after this line (can be 0) */
|
||||||
|
char_u *line, /* text of the new line */
|
||||||
|
colnr_T len, /* length of new line, including NUL, or 0 */
|
||||||
|
int newfile) /* flag, see above */
|
||||||
|
{
|
||||||
|
/* When starting up, we might still need to create the memfile */
|
||||||
|
if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
return ml_append_flush(curbuf, lnum, line, len, newfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FEAT_SPELL) || defined(FEAT_QUICKFIX) || defined(PROTO)
|
||||||
|
/*
|
||||||
|
* Like ml_append() but for an arbitrary buffer. The buffer must already have
|
||||||
|
* a memline.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ml_append_buf(
|
||||||
|
buf_T *buf,
|
||||||
|
linenr_T lnum, /* append after this line (can be 0) */
|
||||||
|
char_u *line, /* text of the new line */
|
||||||
|
colnr_T len, /* length of new line, including NUL, or 0 */
|
||||||
|
int newfile) /* flag, see above */
|
||||||
|
{
|
||||||
|
if (buf->b_ml.ml_mfp == NULL)
|
||||||
|
return FAIL;
|
||||||
|
return ml_append_flush(buf, lnum, line, len, newfile);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replace line lnum, with buffering, in current buffer.
|
* Replace line lnum, with buffering, in current buffer.
|
||||||
*
|
*
|
||||||
|
@@ -777,6 +777,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1700,
|
||||||
/**/
|
/**/
|
||||||
1699,
|
1699,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user