about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-12 14:24:11 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-14 10:17:07 +0100
commitbc571a387d3fa82e1746a7c7c2dc80283879a1ec (patch)
tree20ab0592fd9b067f9f4ab133bd30cf3d2afc3020
parent4ec005e4c3563066e33e0cf7b87dd027489f03bc (diff)
downloadprofani-tty-bc571a387d3fa82e1746a7c7c2dc80283879a1ec.tar.gz
xep-0308: Add autocompletion of last message for /correct
-rw-r--r--src/command/cmd_ac.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 17629d87..386e8939 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -3742,8 +3742,33 @@ _correction_autocomplete(ProfWin *window, const char *const input, gboolean prev
 static char*
 _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous)
 {
-    char *result = NULL;
-
-    //TODO: get last message
-    return result;
+	char *last_message = NULL;
+	switch(window->type) {
+	case WIN_CHAT:
+	{
+		ProfChatWin *chatwin = (ProfChatWin*)window;
+		assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+		last_message = chatwin->last_message;
+		break;
+	}
+	case WIN_MUC:
+	{
+		ProfMucWin *mucwin = (ProfMucWin*)window;
+		assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+		last_message = mucwin->last_message;
+	}
+	default:
+		break;
+	}
+
+	if (last_message == NULL) {
+		return NULL;
+	}
+
+	GString *result_str = g_string_new("/correct ");
+	g_string_append(result_str, last_message);
+	char *result = result_str->str;
+	g_string_free(result_str, FALSE);
+
+	return result;
 }
f='#n158'>158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214