changeset 15124:ed14c190a868

[gaim-migrate @ 17910] 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. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 07 Dec 2006 06:43:37 +0000
parents c8957b9c6202
children 1bd757119ca7
files console/libgnt/gntentry.c doc/gaim-text.1.in
diffstat 2 files changed, 72 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntentry.c	Thu Dec 07 05:57:53 2006 +0000
+++ b/console/libgnt/gntentry.c	Thu Dec 07 06:43:37 2006 +0000
@@ -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,
--- a/doc/gaim-text.1.in	Thu Dec 07 05:57:53 2006 +0000
+++ b/doc/gaim-text.1.in	Thu Dec 07 06:43:37 2006 +0000
@@ -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