From: <sa...@us...> - 2006-12-07 06:48:30
|
Revision: 17910 http://svn.sourceforge.net/gaim/?rev=17910&view=rev Author: sadrul Date: 2006-12-06 22:43:37 -0800 (Wed, 06 Dec 2006) Log Message: ----------- Fix cursor-prev-word and delete-prev-word for non-ascii characters. Add new action cursor-next-word with a-f as the default binding. Update the manpage for the changes. Modified Paths: -------------- trunk/console/libgnt/gntentry.c trunk/doc/gaim-text.1.in Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-12-07 05:57:53 UTC (rev 17909) +++ trunk/console/libgnt/gntentry.c 2006-12-07 06:43:37 UTC (rev 17910) @@ -334,28 +334,49 @@ return TRUE; } +#define SAME(a,b) ((g_unichar_isalpha(a) && g_unichar_isalpha(b)) || \ + (g_unichar_isdigit(a) && g_unichar_isdigit(b)) || \ + (g_unichar_isspace(a) && g_unichar_isspace(b)) || \ + (g_unichar_iswide(a) && g_unichar_iswide(b))) + static const char * begin_word(const char *text, const char *begin) { - char ch; - while (text > begin && (isspace(*text) || !*text)) - text--; - ch = *text; -#define SAME(a,b) ((isalpha(a) && isalpha(b)) || (isdigit(a) && isdigit(b)) || (isspace(a) && isspace(b))) - while (--text >= begin) { - if (!SAME(ch, *text)) + gunichar ch = 0; + while (text > begin && (!*text || g_unichar_isspace(g_utf8_get_char(text)))) + text = g_utf8_find_prev_char(begin, text); + ch = g_utf8_get_char(text); + while ((text = g_utf8_find_prev_char(begin, text)) >= begin) { + gunichar cur = g_utf8_get_char(text); + if (!SAME(ch, cur)) break; } -#undef SAME - return ++text; + return (text ? g_utf8_find_next_char(text, NULL) : begin); } +static const char * +next_begin_word(const char *text, const char *end) +{ + gunichar ch = 0; + ch = g_utf8_get_char(text); + while ((text = g_utf8_find_next_char(text, end)) != NULL && text <= end) { + gunichar cur = g_utf8_get_char(text); + if (!SAME(ch, cur)) + break; + } + + while (text && text < end && g_unichar_isspace(g_utf8_get_char(text))) + text = g_utf8_find_next_char(text, end); + return (text ? text : end); +} + +#undef SAME static gboolean move_back_word(GntBindable *bind, GList *null) { GntEntry *entry = GNT_ENTRY(bind); - const char *iter = entry->cursor - 1; + const char *iter = g_utf8_find_prev_char(entry->start, entry->cursor); if (iter < entry->start) return TRUE; @@ -372,7 +393,7 @@ { GntWidget *widget = GNT_WIDGET(bind); GntEntry *entry = GNT_ENTRY(bind); - char *iter = entry->cursor - 1; + char *iter = g_utf8_find_prev_char(entry->start, entry->cursor); int count; if (iter < entry->start) @@ -394,6 +415,32 @@ } static gboolean +move_forward_word(GntBindable *bind, GList *list) +{ + GntEntry *entry = GNT_ENTRY(bind); + GntWidget *widget = GNT_WIDGET(bind); + entry->cursor = (char *)next_begin_word(entry->cursor, entry->end); + while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) { + entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); + } + entry_redraw(widget); + return TRUE; +} + +static gboolean +move_forward_word(GntBindable *bind, GList *list) +{ + GntEntry *entry = GNT_ENTRY(bind); + GntWidget *widget = GNT_WIDGET(bind); + entry->cursor = (char *)next_begin_word(entry->cursor, entry->end); + while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) { + entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); + } + entry_redraw(widget); + return TRUE; +} + +static gboolean gnt_entry_key_pressed(GntWidget *widget, const char *text) { GntEntry *entry = GNT_ENTRY(widget); @@ -571,13 +618,17 @@ NULL, 1, NULL); #endif gnt_bindable_class_register_action(bindable, "cursor-prev-word", move_back_word, - NULL, NULL); + "\033" "b", NULL); gnt_bindable_class_register_action(bindable, "cursor-prev", move_back, GNT_KEY_LEFT, NULL); gnt_bindable_register_binding(bindable, "cursor-prev", GNT_KEY_CTRL_B, NULL); gnt_bindable_class_register_action(bindable, "cursor-next", move_forward, GNT_KEY_RIGHT, NULL); gnt_bindable_register_binding(bindable, "cursor-next", GNT_KEY_CTRL_F, NULL); + gnt_bindable_class_register_action(bindable, "cursor-next-word", move_forward_word, + "\033" "f", NULL); + gnt_bindable_class_register_action(bindable, "cursor-next-word", delete_forward_word, + "\033" "d", NULL); gnt_bindable_class_register_action(bindable, "suggest-show", suggest_show, "\t", NULL); gnt_bindable_class_register_action(bindable, "suggest-next", suggest_next, Modified: trunk/doc/gaim-text.1.in =================================================================== --- trunk/doc/gaim-text.1.in 2006-12-07 05:57:53 UTC (rev 17909) +++ trunk/doc/gaim-text.1.in 2006-12-07 06:43:37 UTC (rev 17910) @@ -245,11 +245,11 @@ .br up = suggest-prev .br -# The following actions don't have any default binding: +c-w = delete-prev-word .br -# delete-prev-word +a-b = cursor-prev-word .br -# cursor-prev-word +a-f = cursor-next-word .br [GntTree::binding] @@ -266,10 +266,13 @@ .br pagedown = page-down .br +# Following is the default binding for the context-menu +.br +menu = context-menu +.br # The following will let you open the context-menu in the buddylist with c-b .br -c-b = context-menu -.br +# c-b = context-menu .br [GntWidget::binding] @@ -341,7 +344,7 @@ .br [GntS::binding] .br -c-t = toggle-buddylist +a-b = toggle-buddylist .SH Conversation Commands There are a few helpful commands in addition to the regular commands. You can This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |