1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Highlight links as one enters link prefixes.

This commit is contained in:
Miciah Dashiel Butler Masters 2006-04-14 21:46:35 +00:00 committed by Miciah Dashiel Butler Masters
parent 6d0fe1e28f
commit 90f71fe6e4
3 changed files with 44 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}