From 9e5d79a8038a2843876d015309bfb478bdd642a1 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sat, 2 Aug 2008 00:04:13 +0000 Subject: [PATCH] Follow right link when link onClick changes docs When a link had an onClick event handler that changed the current document and that link was clicked, ELinks would follow the current link of the document displayed after executing the handler instead of the link that was clicked. Factor goto_link out of goto_current_link. Use goto_link instead of goto_current_link in activate_link to ensure that the link that is passed in by enter() is followed. --- src/viewer/text/link.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c index a9021b0f..c42981b6 100644 --- a/src/viewer/text/link.c +++ b/src/viewer/text/link.c @@ -943,18 +943,14 @@ call_onsubmit_and_submit(struct session *ses, struct document_view *doc_view, return 1; } -struct link * -goto_current_link(struct session *ses, struct document_view *doc_view, int do_reload) +static struct link * +goto_link(struct session *ses, struct document_view *doc_view, struct link *link, int do_reload) { - struct link *link; struct uri *uri; - assert(doc_view && ses); + assert(link && doc_view && ses); if_assert_failed return NULL; - link = get_current_link(doc_view); - if (!link) return NULL; - if (link_is_form(link)) { struct form_control *fc = link->data.form_control; @@ -983,6 +979,20 @@ goto_current_link(struct session *ses, struct document_view *doc_view, int do_re return link; } +struct link * +goto_current_link(struct session *ses, struct document_view *doc_view, int do_reload) +{ + struct link *link; + + assert(doc_view && ses); + if_assert_failed return NULL; + + link = get_current_link(doc_view); + if (!link) return NULL; + + return goto_link(ses, doc_view, link, do_reload); +} + static enum frame_event_status activate_link(struct session *ses, struct document_view *doc_view, struct link *link, int do_reload) @@ -997,7 +1007,7 @@ activate_link(struct session *ses, struct document_view *doc_view, case LINK_FIELD: case LINK_AREA: case LINK_BUTTON: - if (goto_current_link(ses, doc_view, do_reload)) + if (goto_link(ses, doc_view, link, do_reload)) return FRAME_EVENT_OK; break; case LINK_CHECKBOX: