Mercurial > vim
comparison src/edit.c @ 3095:dc7f2f975920 v7.3.319
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)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 21 Sep 2011 18:23:05 +0200 |
parents | 2cbde6bcc623 |
children | ff69efc4bc55 |
comparison
equal
deleted
inserted
replaced
3094:93d872f58f5e | 3095:dc7f2f975920 |
---|---|
161 static int ins_compl_len __ARGS((void)); | 161 static int ins_compl_len __ARGS((void)); |
162 static void ins_compl_restart __ARGS((void)); | 162 static void ins_compl_restart __ARGS((void)); |
163 static void ins_compl_set_original_text __ARGS((char_u *str)); | 163 static void ins_compl_set_original_text __ARGS((char_u *str)); |
164 static void ins_compl_addfrommatch __ARGS((void)); | 164 static void ins_compl_addfrommatch __ARGS((void)); |
165 static int ins_compl_prep __ARGS((int c)); | 165 static int ins_compl_prep __ARGS((int c)); |
166 static void ins_compl_fixRedoBufForLeader __ARGS((char_u *ptr_arg)); | |
166 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag)); | 167 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag)); |
167 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) | 168 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) |
168 static void ins_compl_add_list __ARGS((list_T *list)); | 169 static void ins_compl_add_list __ARGS((list_T *list)); |
169 static void ins_compl_add_dict __ARGS((dict_T *dict)); | 170 static void ins_compl_add_dict __ARGS((dict_T *dict)); |
170 #endif | 171 #endif |
3711 /* Get here when we have finished typing a sequence of ^N and | 3712 /* Get here when we have finished typing a sequence of ^N and |
3712 * ^P or other completion characters in CTRL-X mode. Free up | 3713 * ^P or other completion characters in CTRL-X mode. Free up |
3713 * memory that was used, and make sure we can redo the insert. */ | 3714 * memory that was used, and make sure we can redo the insert. */ |
3714 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E) | 3715 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E) |
3715 { | 3716 { |
3716 char_u *p; | |
3717 int temp = 0; | |
3718 | |
3719 /* | 3717 /* |
3720 * If any of the original typed text has been changed, eg when | 3718 * If any of the original typed text has been changed, eg when |
3721 * ignorecase is set, we must add back-spaces to the redo | 3719 * ignorecase is set, we must add back-spaces to the redo |
3722 * buffer. We add as few as necessary to delete just the part | 3720 * buffer. We add as few as necessary to delete just the part |
3723 * of the original text that has changed. | 3721 * of the original text that has changed. |
3724 * When using the longest match, edited the match or used | 3722 * When using the longest match, edited the match or used |
3725 * CTRL-E then don't use the current match. | 3723 * CTRL-E then don't use the current match. |
3726 */ | 3724 */ |
3727 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) | 3725 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) |
3728 ptr = compl_curr_match->cp_str; | 3726 ptr = compl_curr_match->cp_str; |
3729 else if (compl_leader != NULL) | |
3730 ptr = compl_leader; | |
3731 else | 3727 else |
3732 ptr = compl_orig_text; | 3728 ptr = NULL; |
3733 if (compl_orig_text != NULL) | 3729 ins_compl_fixRedoBufForLeader(ptr); |
3734 { | |
3735 p = compl_orig_text; | |
3736 for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp]; | |
3737 ++temp) | |
3738 ; | |
3739 #ifdef FEAT_MBYTE | |
3740 if (temp > 0) | |
3741 temp -= (*mb_head_off)(compl_orig_text, p + temp); | |
3742 #endif | |
3743 for (p += temp; *p != NUL; mb_ptr_adv(p)) | |
3744 AppendCharToRedobuff(K_BS); | |
3745 } | |
3746 if (ptr != NULL) | |
3747 AppendToRedobuffLit(ptr + temp, -1); | |
3748 } | 3730 } |
3749 | 3731 |
3750 #ifdef FEAT_CINDENT | 3732 #ifdef FEAT_CINDENT |
3751 want_cindent = (can_cindent && cindent_on()); | 3733 want_cindent = (can_cindent && cindent_on()); |
3752 #endif | 3734 #endif |
3829 compl_cont_status = 0; | 3811 compl_cont_status = 0; |
3830 compl_cont_mode = 0; | 3812 compl_cont_mode = 0; |
3831 } | 3813 } |
3832 | 3814 |
3833 return retval; | 3815 return retval; |
3816 } | |
3817 | |
3818 /* | |
3819 * Fix the redo buffer for the completion leader replacing some of the typed | |
3820 * text. This inserts backspaces and appends the changed text. | |
3821 * "ptr" is the known leader text or NUL. | |
3822 */ | |
3823 static void | |
3824 ins_compl_fixRedoBufForLeader(ptr_arg) | |
3825 char_u *ptr_arg; | |
3826 { | |
3827 int len; | |
3828 char_u *p; | |
3829 char_u *ptr = ptr_arg; | |
3830 | |
3831 if (ptr == NULL) | |
3832 { | |
3833 if (compl_leader != NULL) | |
3834 ptr = compl_leader; | |
3835 else | |
3836 return; /* nothing to do */ | |
3837 } | |
3838 if (compl_orig_text != NULL) | |
3839 { | |
3840 p = compl_orig_text; | |
3841 for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) | |
3842 ; | |
3843 #ifdef FEAT_MBYTE | |
3844 if (len > 0) | |
3845 len -= (*mb_head_off)(p, p + len); | |
3846 #endif | |
3847 for (p += len; *p != NUL; mb_ptr_adv(p)) | |
3848 AppendCharToRedobuff(K_BS); | |
3849 } | |
3850 else | |
3851 len = 0; | |
3852 if (ptr != NULL) | |
3853 AppendToRedobuffLit(ptr + len, -1); | |
3834 } | 3854 } |
3835 | 3855 |
3836 /* | 3856 /* |
3837 * Loops through the list of windows, loaded-buffers or non-loaded-buffers | 3857 * Loops through the list of windows, loaded-buffers or non-loaded-buffers |
3838 * (depending on flag) starting from buf and looking for a non-scanned | 3858 * (depending on flag) starting from buf and looking for a non-scanned |
5239 if (compl_cont_status & CONT_LOCAL) | 5259 if (compl_cont_status & CONT_LOCAL) |
5240 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]); | 5260 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]); |
5241 else | 5261 else |
5242 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); | 5262 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); |
5243 | 5263 |
5264 /* If any of the original typed text has been changed we need to fix | |
5265 * the redo buffer. */ | |
5266 ins_compl_fixRedoBufForLeader(NULL); | |
5267 | |
5244 /* Always add completion for the original text. */ | 5268 /* Always add completion for the original text. */ |
5245 vim_free(compl_orig_text); | 5269 vim_free(compl_orig_text); |
5246 compl_orig_text = vim_strnsave(line + compl_col, compl_length); | 5270 compl_orig_text = vim_strnsave(line + compl_col, compl_length); |
5247 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, | 5271 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, |
5248 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) | 5272 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) |