From: <sa...@us...> - 2006-10-28 06:01:36
|
Revision: 17595 http://svn.sourceforge.net/gaim/?rev=17595&view=rev Author: sadrul Date: 2006-10-27 23:01:30 -0700 (Fri, 27 Oct 2006) Log Message: ----------- Two new actions for the entry box: "delete-prev-word" and "cursor-prev-word". I haven't set any default binding for either. But I think ctrl-w is a common binding for the first action. Modified Paths: -------------- trunk/console/libgnt/gntentry.c Modified: trunk/console/libgnt/gntentry.c =================================================================== --- trunk/console/libgnt/gntentry.c 2006-10-28 04:59:07 UTC (rev 17594) +++ trunk/console/libgnt/gntentry.c 2006-10-28 06:01:30 UTC (rev 17595) @@ -334,7 +334,64 @@ return TRUE; } +static const char * +begin_word(const char *text, const char *begin) +{ + char ch; + ch = *text; +#define SAME(a,b) ((isalpha(a) && isalpha(b)) || (isdigit(a) && isdigit(b)) || (isblank(a) && isblank(b))) + while (--text >= begin) { + if (!SAME(ch, *text)) + break; + } +#undef SAME + + return ++text; +} + static gboolean +move_back_word(GntWidget *widget, GList *null) +{ + GntEntry *entry = GNT_ENTRY(widget); + const char *iter = entry->cursor - 1; + int count; + + if (iter < entry->start) + return TRUE; + iter = begin_word(iter, entry->start); + entry->cursor = (char*)iter; + if (entry->cursor < entry->scroll) + entry->scroll = entry->cursor; + entry_redraw(widget); + return TRUE; +} + +static gboolean +del_prev_word(GntWidget *widget, GList *null) +{ + GntEntry *entry = GNT_ENTRY(widget); + char *iter = entry->cursor - 1; + int count; + + if (iter < entry->start) + return TRUE; + iter = (char*)begin_word(iter, entry->start); + count = entry->cursor - iter; + memmove(iter, entry->cursor, entry->end - entry->cursor); + entry->end -= count; + entry->cursor = iter; + if (entry->cursor <= entry->scroll) { + entry->scroll = entry->cursor - widget->priv.width + 2; + if (entry->scroll < entry->start) + entry->scroll = entry->start; + } + memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); + entry_redraw(widget); + + return TRUE; +} + +static gboolean gnt_entry_key_pressed(GntWidget *widget, const char *text) { GntEntry *entry = GNT_ENTRY(widget); @@ -506,12 +563,14 @@ GNT_KEY_CTRL_U, NULL); gnt_widget_class_register_action(parent_class, "delete-end", del_to_end, GNT_KEY_CTRL_K, NULL); + gnt_widget_class_register_action(parent_class, "delete-prev-word", del_prev_word, + NULL, NULL); #if 0 - gnt_widget_class_register_action(parent_class, "delete-prev-word", del_prev_word, - NULL, 1, NULL); gnt_widget_class_register_action(parent_class, "delete-next-word", del_next_word, NULL, 1, NULL); #endif + gnt_widget_class_register_action(parent_class, "cursor-prev-word", move_back_word, + NULL, NULL); gnt_widget_class_register_action(parent_class, "cursor-prev", move_back, "\033" GNT_KEY_LEFT, NULL); gnt_widget_class_register_action(parent_class, "cursor-next", move_forward, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |