From 3aadfc6765b3560dce639b22abb05503aba47bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 21 Jul 2014 21:29:44 +0200 Subject: core: fix insert of mouse code in input line after a partial key combo (closes #130) --- ChangeLog.asciidoc | 2 ++ src/gui/gui-key.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index 6ce3bb0cf..f52acf668 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -15,6 +15,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 1.0 (under dev) +* core: fix insert of mouse code in input line after a partial key combo + (closes #130) * core: check code point value in UTF-8 check function (closes #108) * core: display a warning on startup if $TERM is not screen(-256color) under screen/tmux diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 618c48854..4cbaaea52 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -1239,6 +1239,34 @@ end: return rc; } +/* + * Checks if the given combo of keys is complete or not. + * It's not complete if the end of string is in the middle of a key + * (for example meta- without the following char/key). + * + * Returns: + * 0: key is incomplete (truncated) + * 1: key is complete + */ + +int +gui_key_is_complete (const char *key) +{ + int length; + + if (!key || !key[0]) + return 1; + + length = strlen (key); + + if (((length >= 1) && (strcmp (key + length - 1, "\x01") == 0)) + || ((length >= 2) && (strcmp (key + length - 2, "\x01[") == 0)) + || ((length >= 3) && (strcmp (key + length - 3, "\x01[[") == 0))) + return 0; + + return 1; +} + /* * Processes a new key pressed. * @@ -1289,7 +1317,7 @@ gui_key_pressed (const char *key_str) return 0; } - if (strcmp (gui_key_combo_buffer, "\x01[[M") == 0) + if (strstr (gui_key_combo_buffer, "\x01[[M")) { gui_key_combo_buffer[0] = '\0'; gui_mouse_event_init (); @@ -1389,7 +1417,8 @@ gui_key_pressed (const char *key_str) } } - gui_key_combo_buffer[0] = '\0'; + if (gui_key_is_complete (gui_key_combo_buffer)) + gui_key_combo_buffer[0] = '\0'; /* * if this is first key and not found (even partial) => return 1 -- cgit v1.2.3