From eb3a92c99ee48f67f797ba69800af3196afbf031 Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Fri, 14 Feb 2020 04:04:07 -0500 Subject: Don't copy into cut buffer during tab complete --- edit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'edit.c') diff --git a/edit.c b/edit.c index 1f8f170..997feed 100644 --- a/edit.c +++ b/edit.c @@ -60,9 +60,9 @@ static bool reserve(size_t index, size_t count) { return true; } -static void delete(size_t index, size_t count) { +static void delete(bool copy, size_t index, size_t count) { if (index + count > len) return; - if (count > 1) { + if (copy) { memcpy(cut.buf, &buf[index], sizeof(*buf) * count); cut.len = count; } @@ -109,7 +109,7 @@ static void tabComplete(size_t id) { return; } - delete(tab.pos, tab.len); + delete(false, tab.pos, tab.len); if (wcs[0] != L'/' && !tab.pos) { tab.len = n + 2; reserve(tab.pos, tab.len); @@ -158,22 +158,22 @@ void edit(size_t id, enum Edit op, wchar_t ch) { while (pos < len && !iswspace(buf[pos])) pos++; } - break; case EditDeleteHead: delete(0, pos); pos = 0; - break; case EditDeleteTail: delete(pos, len - pos); - break; case EditDeletePrev: if (pos) delete(--pos, 1); - break; case EditDeleteNext: delete(pos, 1); + break; case EditDeleteHead: delete(true, 0, pos); pos = 0; + break; case EditDeleteTail: delete(true, pos, len - pos); + break; case EditDeletePrev: if (pos) delete(false, --pos, 1); + break; case EditDeleteNext: delete(false, pos, 1); break; case EditDeletePrevWord: { if (!pos) break; size_t word = pos - 1; while (word && !iswspace(buf[word - 1])) word--; - delete(word, pos - word); + delete(true, word, pos - word); pos = word; } break; case EditDeleteNextWord: { if (pos == len) break; size_t word = pos + 1; while (word < len && !iswspace(buf[word])) word++; - delete(pos, word - pos); + delete(true, pos, word - pos); } break; case EditPaste: { if (reserve(pos, cut.len)) { -- cgit 1.4.1-2-gfad0