# HG changeset patch # User Sadrul Habib Chowdhury # Date 1162015290 0 # Node ID 91a89d5ef714b1cb46845a991ebd5f7d85ebf8df # Parent 02b70dc430442058b64958282eac5d43e40dd362 [gaim-migrate @ 17595] 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. committer: Tailor Script diff -r 02b70dc43044 -r 91a89d5ef714 console/libgnt/gntentry.c --- a/console/libgnt/gntentry.c Sat Oct 28 04:59:07 2006 +0000 +++ b/console/libgnt/gntentry.c Sat Oct 28 06:01:30 2006 +0000 @@ -334,6 +334,63 @@ 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) { @@ -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,