>From fc9785f0cf84f158e244fc668e65d8163d37ad69 Mon Sep 17 00:00:00 2001 From: "sumedh.pendurkar" Date: Sun, 6 Nov 2016 11:29:22 +0530 Subject: [PATCH 5/5] replaced charmove by do_undo; also fixed issue when wrapping is enabled --- src/text.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/text.c b/src/text.c index 516f4ce..d95d2e1 100644 --- a/src/text.c +++ b/src/text.c @@ -50,8 +50,6 @@ static filestruct *jusbottom = NULL; static int pletion_x = 0; /* The x position in pletion_line of the last found completion. */ -static int pleted_length = 0; - /* The number of bytes added in the last completion. */ static completion_word *list_of_completions; /* A linked list of the words that are possible completions. */ @@ -817,7 +815,7 @@ void do_undo(void) break; } - if (undidmsg) + if (!pletion_line && undidmsg) statusline(HUSH, _("Undid action (%s)"), undidmsg); renumber(f); @@ -3727,6 +3725,7 @@ void complete_a_word(void) int start_of_shard, shard_length = 0; int i = 0, j = 0; completion_word *some_word; + bool was_set_wrapping = !ISSET(NO_WRAP); /* If this is a fresh completion attempt... */ if (pletion_line == NULL) { @@ -3750,16 +3749,11 @@ void complete_a_word(void) wnoutrefresh(bottomwin); } else { /* Remove the earlier completion from the buffer. */ - openfile->current_x -= pleted_length; - charmove(openfile->current->data + openfile->current_x, - openfile->current->data + openfile->current_x + pleted_length, - strlen(openfile->current->data + openfile->current_x) - pleted_length + 1); - openfile->totsize -= pleted_length; + do_undo(); /* Pop the last undo item off the stack, because the completion * suggestion should not be remembered. */ - discard_until(openfile->current_undo->next, openfile); - openfile->current_undo = openfile->undotop; + discard_until(openfile->current_undo, openfile); } /* Find the start of the fragment that the user typed. */ @@ -3838,9 +3832,16 @@ void complete_a_word(void) some_word->next = list_of_completions; list_of_completions = some_word; - /* Inject the completion into the buffer. */ - pleted_length = strlen(completion) - shard_length; - do_output(&some_word->word[shard_length], pleted_length, FALSE); + /* Inject the completion into the buffer. + * Also temporarily disable wrapping and do_wrap after do_output so that only + * one item is added in undo stack and then reset wrapping */ + SET(NO_WRAP); + do_output(&some_word->word[shard_length], + strlen(completion) - shard_length, FALSE); + if (was_set_wrapping) { + UNSET(NO_WRAP); + do_wrap(openfile->current); + } /* Mark the position for a possible next search attempt. */ pletion_x = ++i; -- 2.7.4