summary refs log tree commit diff
path: root/edit.c
diff options
context:
space:
mode:
authorC. McEnroe2020-02-14 04:04:07 -0500
committerC. McEnroe2020-02-14 04:04:07 -0500
commiteb3a92c99ee48f67f797ba69800af3196afbf031 (patch)
tree5f44ad9fdddae0809a024a580d0891f0e8e51c6c /edit.c
parent3b257a55c3d989a601589beaf12fb5a197508e37 (diff)
Don't copy into cut buffer during tab complete
Diffstat (limited to 'edit.c')
-rw-r--r--edit.c18
1 files changed, 9 insertions, 9 deletions
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)) {