summary refs log tree commit diff
path: root/edit.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-07 10:48:44 -0400
committerJune McEnroe <june@causal.agency>2020-04-07 10:48:44 -0400
commite3f7362241a82d2089a45d119b86109c9d89ec8f (patch)
treec07c14f663ae4d21c2c5eb38353c72161051b99a /edit.c
parentAdd split scrolling to README (diff)
downloadcatgirl-e3f7362241a82d2089a45d119b86109c9d89ec8f.tar.gz
catgirl-e3f7362241a82d2089a45d119b86109c9d89ec8f.zip
Add M-q to collapse whitespace
Diffstat (limited to '')
-rw-r--r--edit.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/edit.c b/edit.c
index 1b23737..a37a3e4 100644
--- a/edit.c
+++ b/edit.c
@@ -232,6 +232,19 @@ void edit(uint id, enum Edit op, wchar_t ch) {
 			buf[pos - 1] = buf[pos];
 			buf[pos++] = t;
 		}
+		break; case EditCollapse: {
+			size_t ws;
+			for (pos = 0; pos < len;) {
+				for (; pos < len && !iswspace(buf[pos]); ++pos);
+				for (ws = pos; ws < len && iswspace(buf[ws]); ++ws);
+				if (pos && ws < len) {
+					delete(false, pos, ws - pos - 1);
+					buf[pos++] = L' ';
+				} else {
+					delete(false, pos, ws - pos);
+				}
+			}
+		}
 
 		break; case EditInsert: {
 			if (reserve(pos, 1)) {