From 90f71fe6e455f568f1b0810cda17db56ae1426f6 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 14 Apr 2006 21:46:35 +0000 Subject: [PATCH 1/2] Highlight links as one enters link prefixes. --- src/viewer/text/link.c | 33 +++++++++++++++++++++++++++++++++ src/viewer/text/link.h | 4 ++++ src/viewer/text/view.c | 7 +++++++ 3 files changed, 44 insertions(+) diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c index 3e10d6fe..90f48809 100644 --- a/src/viewer/text/link.c +++ b/src/viewer/text/link.c @@ -11,6 +11,7 @@ #include "bfu/listmenu.h" #include "bfu/menu.h" +#include "bfu/style.h" #include "dialogs/menu.h" #include "dialogs/status.h" #include "document/document.h" @@ -31,6 +32,7 @@ #include "terminal/screen.h" #include "terminal/tab.h" #include "terminal/terminal.h" +#include "util/box.h" #include "util/conv.h" #include "util/error.h" #include "util/memory.h" @@ -320,6 +322,37 @@ clear_link(struct terminal *term, struct document_view *doc_view) } } +void +highlight_links_with_prefixes_that_start_with_n(struct terminal *term, + struct document_view *doc_view, + int n) +{ + struct color_pair *color = get_bfu_color(term, "searched"); + int xoffset = doc_view->box.x - doc_view->vs->x; + int yoffset = doc_view->box.y - doc_view->vs->y; + struct document *document = doc_view->document; + int m; + + for (m = n + 1; n <= document->nlinks; n *= 10, m *= 10) { + int linkn; + + for (linkn = n; linkn < m; ++linkn) { + struct link *link = &document->links[linkn - 1]; + int i; + + if (linkn > document->nlinks) break; + + for (i = 0; i < link->npoints; ++i) { + int x = link->points[i].x + xoffset; + int y = link->points[i].y + yoffset; + + if (is_in_box(&doc_view->box, x, y)) + draw_char_color(term, x, y, color); + } + } + } +} + struct link * get_first_link(struct document_view *doc_view) { diff --git a/src/viewer/text/link.h b/src/viewer/text/link.h index 6014be88..4cfc5491 100644 --- a/src/viewer/text/link.h +++ b/src/viewer/text/link.h @@ -17,6 +17,10 @@ void free_link(struct document_view *doc_view); void clear_link(struct terminal *term, struct document_view *doc_view); void draw_current_link(struct session *ses, struct document_view *doc_view); +void highlight_links_with_prefixes_that_start_with_n(struct terminal *term, + struct document_view *doc_view, + int n); + void link_menu(struct terminal *term, void *, void *ses); struct link *get_first_link(struct document_view *doc_view); diff --git a/src/viewer/text/view.c b/src/viewer/text/view.c index 24f6606d..f135528b 100644 --- a/src/viewer/text/view.c +++ b/src/viewer/text/view.c @@ -689,6 +689,9 @@ try_prefix_key(struct session *ses, struct document_view *doc_view, * the first time by init_session() calloc() call. * When used, it has to be reset to zero. */ + /* Clear the highlighting for the previous partial prefix. */ + if (ses->kbdprefix.repeat_count) draw_formatted(ses, 0); + ses->kbdprefix.repeat_count *= 10; ses->kbdprefix.repeat_count += digit; @@ -696,6 +699,10 @@ try_prefix_key(struct session *ses, struct document_view *doc_view, * '0' six times or more will reset the count. */ if (ses->kbdprefix.repeat_count > 99999) ses->kbdprefix.repeat_count = 0; + else if (ses->kbdprefix.repeat_count) + highlight_links_with_prefixes_that_start_with_n( + ses->tab->term, doc_view, + ses->kbdprefix.repeat_count); return FRAME_EVENT_OK; } From 8adb9768855f7b30cac1873c4e853bec651ceabc Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 14 Apr 2006 21:55:42 +0000 Subject: [PATCH 2/2] Add backspace-prefix to the main map, to backspace the last entered digit of the prefix. --- src/config/actions-main.inc | 1 + src/config/kbdbind.c | 1 + src/viewer/action.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/config/actions-main.inc b/src/config/actions-main.inc index a8a76c96..9626c9dd 100644 --- a/src/config/actions-main.inc +++ b/src/config/actions-main.inc @@ -10,6 +10,7 @@ ACTION_(MAIN, "add-bookmark", ADD_BOOKMARK, N__("Add a new bookmark"), ACTION_RE ACTION_(MAIN, "add-bookmark-link", ADD_BOOKMARK_LINK, N__("Add a new bookmark using current link"), ACTION_RESTRICT_ANONYMOUS | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK), ACTION_(MAIN, "add-bookmark-tabs", ADD_BOOKMARK_TABS, N__("Bookmark all open tabs"), ACTION_RESTRICT_ANONYMOUS), ACTION_(MAIN, "auth-manager", AUTH_MANAGER, N__("Open authentication manager"), 0), +ACTION_(MAIN, "backspace-prefix", BACKSPACE_PREFIX, N__("Backspace the last entered digit of the current prefix"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "bookmark-manager", BOOKMARK_MANAGER, N__("Open bookmark manager"), 0), ACTION_(MAIN, "cache-manager", CACHE_MANAGER, N__("Open cache manager"), 0), ACTION_(MAIN, "cache-minimize", CACHE_MINIMIZE, N__("Free unused cache entries"), 0), diff --git a/src/config/kbdbind.c b/src/config/kbdbind.c index 936dfb0b..0a3e8eba 100644 --- a/src/config/kbdbind.c +++ b/src/config/kbdbind.c @@ -660,6 +660,7 @@ static struct default_kb default_main_keymap[] = { { { '{', KBD_MOD_NONE }, ACT_MAIN_SCROLL_LEFT }, { { '|', KBD_MOD_NONE }, ACT_MAIN_HEADER_INFO }, { { '}', KBD_MOD_NONE }, ACT_MAIN_SCROLL_RIGHT }, + { { KBD_BS, KBD_MOD_NONE }, ACT_MAIN_BACKSPACE_PREFIX }, { { KBD_DEL, KBD_MOD_NONE }, ACT_MAIN_SCROLL_DOWN }, { { KBD_DOWN, KBD_MOD_NONE }, ACT_MAIN_MOVE_LINK_NEXT }, { { KBD_END, KBD_MOD_NONE }, ACT_MAIN_MOVE_DOCUMENT_END }, diff --git a/src/viewer/action.c b/src/viewer/action.c index 673186ac..3089a19f 100644 --- a/src/viewer/action.c +++ b/src/viewer/action.c @@ -127,6 +127,27 @@ do_action(struct session *ses, enum main_action action_id, int verbose) auth_manager(ses); break; + case ACT_MAIN_BACKSPACE_PREFIX: + + if (!ses->kbdprefix.repeat_count) break; + + /* Clear the highlighting. */ + draw_formatted(ses, 0); + + ses->kbdprefix.repeat_count /= 10; + + if (ses->kbdprefix.repeat_count) + highlight_links_with_prefixes_that_start_with_n( + term, doc_view, + ses->kbdprefix.repeat_count); + + print_screen_status(ses); + + /* Keep send_event from resetting repeat_count. */ + status = FRAME_EVENT_SESSION_DESTROYED; + + break; + case ACT_MAIN_BOOKMARK_MANAGER: #ifdef CONFIG_BOOKMARKS bookmark_manager(ses);