Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix centering current index #659

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions zathura/shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,9 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f);
gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura);

gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview);
gtk_widget_show(treeview);
}

if (gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) {
Expand All @@ -1227,7 +1225,6 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume

girara_set_view(session, zathura->ui.index);
index_scroll_to_current_page(zathura);
gtk_widget_show(GTK_WIDGET(zathura->ui.index));
girara_mode_set(zathura->ui.session, zathura->modes.index);
}

Expand Down
12 changes: 11 additions & 1 deletion zathura/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ static gboolean search_current_index(GtkTreeModel* model, GtkTreePath* UNUSED(pa
return FALSE;
}

static void tree_view_scroll_to_cell(zathura_t* zathura)
{
GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreePath* current_path = gtk_tree_path_new_from_string(zathura->global.current_index_path);
gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0);
}

void index_scroll_to_current_page(zathura_t* zathura) {
GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreeModel* model = gtk_tree_view_get_model(tree_view);
Expand All @@ -134,9 +141,12 @@ void index_scroll_to_current_page(zathura_t* zathura) {
gtk_tree_model_foreach(model, search_current_index, &search_data);

GtkTreePath* current_path = gtk_tree_model_get_path(model, &search_data.current_iter);
g_free(zathura->global.current_index_path);
zathura->global.current_index_path = gtk_tree_path_to_string(current_path);
gtk_tree_view_expand_to_path(tree_view, current_path);

g_idle_add(G_SOURCE_FUNC(tree_view_scroll_to_cell), zathura);
gtk_tree_view_set_cursor(tree_view, current_path, NULL, FALSE);
gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0);
gtk_tree_path_free(current_path);
}

Expand Down
3 changes: 3 additions & 0 deletions zathura/zathura.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,9 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
zathura->ui.index = NULL;
}

/* free current index path */
g_free(zathura->global.current_index_path);

gtk_widget_hide(zathura->ui.page_widget);

statusbar_page_number_update(zathura);
Expand Down
1 change: 1 addition & 0 deletions zathura/zathura.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct zathura_s {
GdkModifierType synctex_edit_modmask; /**< Modifier to trigger synctex edit */
GdkModifierType highlighter_modmask; /**< Modifier to draw with a highlighter */
bool double_click_follow; /**< Double/Single click to follow link */
gchar *current_index_path;
} global;

struct {
Expand Down