From 14ae13f781d1ab30d648eaffbace67a9eec36c5b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 12 Feb 2020 01:16:40 -0500 Subject: [PATCH] Add C-t transpose Also in emacs, weechat. --- catgirl.1 | 2 ++ chat.h | 1 + edit.c | 9 +++++++++ ui.c | 3 ++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/catgirl.1 b/catgirl.1 index ad62f83..518f830 100644 --- a/catgirl.1 +++ b/catgirl.1 @@ -265,6 +265,8 @@ Move to end of line. Move right. .It Ic C-k Delete to end of line. +.It Ic C-t +Transpose characters. .It Ic C-u Delete to beginning of line. .It Ic C-w diff --git a/chat.h b/chat.h index 4e9a230..aa2f87c 100644 --- a/chat.h +++ b/chat.h @@ -176,6 +176,7 @@ enum Edit { EditDeletePrevWord, EditDeleteNextWord, EditPaste, + EditTranspose, EditInsert, EditComplete, EditEnter, diff --git a/edit.c b/edit.c index d90d558..573e549 100644 --- a/edit.c +++ b/edit.c @@ -182,6 +182,15 @@ void edit(size_t id, enum Edit op, wchar_t ch) { } } + break; case EditTranspose: { + if (!pos || len < 2) break; + if (pos == len) pos--; + wchar_t t = buf[pos]; + buf[pos] = buf[pos - 1]; + buf[pos - 1] = t; + pos++; + } + break; case EditInsert: { if (reserve(pos, 1)) { buf[pos++] = ch; diff --git a/ui.c b/ui.c index 328db1b..e6041cc 100644 --- a/ui.c +++ b/ui.c @@ -844,9 +844,10 @@ static void keyCtrl(wchar_t ch) { break; case L'N': windowShow(windows.active->next); break; case L'O': windowShow(windows.other); break; case L'P': windowShow(windows.active->prev); + break; case L'T': edit(id, EditTranspose, 0); break; case L'U': edit(id, EditDeleteHead, 0); - break; case L'W': edit(id, EditDeletePrevWord, 0); break; case L'V': windowScroll(windows.active, -(PAGE_LINES - 2)); + break; case L'W': edit(id, EditDeletePrevWord, 0); break; case L'Y': edit(id, EditPaste, 0); } }