From 30ec7ad3a61c71c797f975f27126224666e7b497 Mon Sep 17 00:00:00 2001 From: Ofear Date: Tue, 19 Feb 2013 16:57:29 -0500 Subject: [PATCH] change urlselect overlay to immediately select a link once the number of digits inputted is equal to the number of digits in the largest link --- termite.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/termite.cc b/termite.cc index 211a710..80ce6a5 100644 --- a/termite.cc +++ b/termite.cc @@ -746,6 +746,43 @@ gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, keybind_info *i gboolean ret = FALSE; switch (event->keyval) { + case GDK_KEY_0: + case GDK_KEY_1: + case GDK_KEY_2: + case GDK_KEY_3: + case GDK_KEY_4: + case GDK_KEY_5: + case GDK_KEY_6: + case GDK_KEY_7: + case GDK_KEY_8: + case GDK_KEY_9: + if(info->panel.mode == overlay_mode::urlselect) + { + const char *const text = gtk_entry_get_text(entry); + char* fulltext = g_strndup(text, strlen(text)+1); + fulltext[strlen(text)] = (char)event->keyval; + gboolean exalpha = FALSE; + for(int i = 0; text[i] != '\0'; i++) { + if(!g_ascii_isdigit(text[i])) { + exalpha = TRUE; + break; + } + } + if(exalpha) + break; + char* str_ptr = (char*)malloc(sizeof(text)); + sprintf(str_ptr, "%d", (int)info->panel.url_list.size()); + int url_num = (int)strlen(str_ptr); + delete str_ptr; + int inp_num = (int)strlen(fulltext); + if(url_num == inp_num) + { + launch_url(info->config.browser, fulltext, &info->panel); + ret = TRUE; + } + } + break; + case GDK_KEY_Tab: synthesize_keypress(GTK_WIDGET(entry), GDK_KEY_Down); return TRUE;