1
0
forked from aniani/vim

updated for version 7.3.319

Problem:    Redobuff doesn't always include changes of the completion leader.
Solution:   Insert backspaces as needed. (idea by Taro Muraoka)
This commit is contained in:
Bram Moolenaar
2011-09-21 18:23:05 +02:00
parent a554a1933c
commit 62951b1e0d
2 changed files with 47 additions and 21 deletions

View File

@@ -163,6 +163,7 @@ static void ins_compl_restart __ARGS((void));
static void ins_compl_set_original_text __ARGS((char_u *str)); static void ins_compl_set_original_text __ARGS((char_u *str));
static void ins_compl_addfrommatch __ARGS((void)); static void ins_compl_addfrommatch __ARGS((void));
static int ins_compl_prep __ARGS((int c)); static int ins_compl_prep __ARGS((int c));
static void ins_compl_fixRedoBufForLeader __ARGS((char_u *ptr_arg));
static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag)); static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
#if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
static void ins_compl_add_list __ARGS((list_T *list)); static void ins_compl_add_list __ARGS((list_T *list));
@@ -3713,9 +3714,6 @@ ins_compl_prep(c)
* memory that was used, and make sure we can redo the insert. */ * memory that was used, and make sure we can redo the insert. */
if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E) if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
{ {
char_u *p;
int temp = 0;
/* /*
* If any of the original typed text has been changed, eg when * If any of the original typed text has been changed, eg when
* ignorecase is set, we must add back-spaces to the redo * ignorecase is set, we must add back-spaces to the redo
@@ -3726,25 +3724,9 @@ ins_compl_prep(c)
*/ */
if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
ptr = compl_curr_match->cp_str; ptr = compl_curr_match->cp_str;
else if (compl_leader != NULL)
ptr = compl_leader;
else else
ptr = compl_orig_text; ptr = NULL;
if (compl_orig_text != NULL) ins_compl_fixRedoBufForLeader(ptr);
{
p = compl_orig_text;
for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp];
++temp)
;
#ifdef FEAT_MBYTE
if (temp > 0)
temp -= (*mb_head_off)(compl_orig_text, p + temp);
#endif
for (p += temp; *p != NUL; mb_ptr_adv(p))
AppendCharToRedobuff(K_BS);
}
if (ptr != NULL)
AppendToRedobuffLit(ptr + temp, -1);
} }
#ifdef FEAT_CINDENT #ifdef FEAT_CINDENT
@@ -3833,6 +3815,44 @@ ins_compl_prep(c)
return retval; return retval;
} }
/*
* Fix the redo buffer for the completion leader replacing some of the typed
* text. This inserts backspaces and appends the changed text.
* "ptr" is the known leader text or NUL.
*/
static void
ins_compl_fixRedoBufForLeader(ptr_arg)
char_u *ptr_arg;
{
int len;
char_u *p;
char_u *ptr = ptr_arg;
if (ptr == NULL)
{
if (compl_leader != NULL)
ptr = compl_leader;
else
return; /* nothing to do */
}
if (compl_orig_text != NULL)
{
p = compl_orig_text;
for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len)
;
#ifdef FEAT_MBYTE
if (len > 0)
len -= (*mb_head_off)(p, p + len);
#endif
for (p += len; *p != NUL; mb_ptr_adv(p))
AppendCharToRedobuff(K_BS);
}
else
len = 0;
if (ptr != NULL)
AppendToRedobuffLit(ptr + len, -1);
}
/* /*
* Loops through the list of windows, loaded-buffers or non-loaded-buffers * Loops through the list of windows, loaded-buffers or non-loaded-buffers
* (depending on flag) starting from buf and looking for a non-scanned * (depending on flag) starting from buf and looking for a non-scanned
@@ -5241,6 +5261,10 @@ ins_complete(c)
else else
edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
/* If any of the original typed text has been changed we need to fix
* the redo buffer. */
ins_compl_fixRedoBufForLeader(NULL);
/* Always add completion for the original text. */ /* Always add completion for the original text. */
vim_free(compl_orig_text); vim_free(compl_orig_text);
compl_orig_text = vim_strnsave(line + compl_col, compl_length); compl_orig_text = vim_strnsave(line + compl_col, compl_length);

View File

@@ -709,6 +709,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 */
/**/
319,
/**/ /**/
318, 318,
/**/ /**/