Refactor handle_links

As soon as we found the link, we do not need to look any further.
This commit is contained in:
Andreas Perstinger 2023-04-20 14:55:14 +02:00 committed by Sebastian Ramacher
parent a6859512b5
commit bb84bb4eaa

View file

@ -408,26 +408,24 @@ handle_link(GtkEntry* entry, girara_session_t* session,
index = index - 1;
}
/* set pages to draw links */
bool invalid_index = true;
/* find the link*/
zathura_link_t* link = NULL;
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL || zathura_page_get_visibility(page) == false) {
if (page == NULL || zathura_page_get_visibility(page) == false || eval == false) {
continue;
}
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(G_OBJECT(page_widget), "draw-links", FALSE, NULL);
if (eval == FALSE) {
/* nothing to evaluate */
continue;
link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (link != NULL) {
break;
}
}
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (link != NULL) {
invalid_index = false;
if (eval == TRUE && link == NULL) {
girara_notify(session, GIRARA_WARNING, _("Invalid index '%s' given."), input);
} else {
switch (action) {
case ZATHURA_LINK_ACTION_FOLLOW:
zathura_link_evaluate(zathura, link);
@ -447,11 +445,6 @@ handle_link(GtkEntry* entry, girara_session_t* session,
}
}
}
}
if (eval == TRUE && invalid_index == true) {
girara_notify(session, GIRARA_WARNING, _("Invalid index '%s' given."), input);
}
g_free(input);