Add the ability to scroll half page up or down in index

This commit is contained in:
laomuon 2024-04-05 13:53:41 +02:00
parent b86cb99d22
commit 9cbc60ca94
3 changed files with 32 additions and 2 deletions

View file

@ -38,8 +38,8 @@ libm = cc.find_library('m', required: false)
girara = dependency('girara-gtk3', version: '>=0.4.3', fallback: ['girara', 'girara_dependency']) girara = dependency('girara-gtk3', version: '>=0.4.3', fallback: ['girara', 'girara_dependency'])
glib = dependency('glib-2.0', version: '>=2.72') glib = dependency('glib-2.0', version: '>=2.72')
gio = dependency('gio-unix-2.0', required: host_machine.system() != 'windows') gio = dependency('gio-unix-2.0', required: host_machine.system() != 'windows')
gthread = dependency('gthread-2.0', version: '>=2.74') gthread = dependency('gthread-2.0', version: '>=2.72')
gmodule = dependency('gmodule-no-export-2.0', version: '>=2.74') gmodule = dependency('gmodule-no-export-2.0', version: '>=2.72')
gtk3 = dependency('gtk+-3.0', version: '>=3.24') gtk3 = dependency('gtk+-3.0', version: '>=3.24')
json_glib = dependency('json-glib-1.0') json_glib = dependency('json-glib-1.0')
cairo = dependency('cairo') cairo = dependency('cairo')

View file

@ -509,6 +509,9 @@ void config_load_default(zathura_t* zathura) {
girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL);
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_d, NULL, sc_navigate_index, INDEX, HALF_DOWN, NULL);
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_u, NULL, sc_navigate_index, INDEX, HALF_UP, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_L, NULL, sc_navigate_index, INDEX, EXPAND_ALL, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_L, NULL, sc_navigate_index, INDEX, EXPAND_ALL, NULL);

View file

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: Zlib */ /* SPDX-License-Identifier: Zlib */
#include <girara/log.h>
#include <girara/session.h> #include <girara/session.h>
#include <girara/settings.h> #include <girara/settings.h>
#include <girara/datastructures.h> #include <girara/datastructures.h>
@ -1035,17 +1036,28 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data; GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
GtkTreePath *path; GtkTreePath *path;
GtkTreePath *start_path;
GtkTreePath *end_path;
gtk_tree_view_get_cursor(tree_view, &path, NULL); gtk_tree_view_get_cursor(tree_view, &path, NULL);
if (path == NULL) { if (path == NULL) {
return false; return false;
} }
if (gtk_tree_view_get_visible_range(tree_view, &start_path, &end_path) != TRUE)
{
girara_error("Cannot get visible range for index");
gtk_tree_path_free(start_path);
gtk_tree_path_free(end_path);
return false;
}
GtkTreeModel *model = gtk_tree_view_get_model(tree_view); GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeIter child_iter; GtkTreeIter child_iter;
gboolean is_valid_path = TRUE; gboolean is_valid_path = TRUE;
gboolean need_to_scroll = FALSE;
switch(argument->n) { switch(argument->n) {
case TOP: case TOP:
@ -1101,6 +1113,18 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
&& gtk_tree_path_up(path)); && gtk_tree_path_up(path));
} }
break; break;
case HALF_UP:
gtk_tree_path_free(path);
gtk_tree_path_free(end_path);
path = start_path;
need_to_scroll = TRUE;
break;
case HALF_DOWN:
gtk_tree_path_free(path);
gtk_tree_path_free(start_path);
path = end_path;
need_to_scroll = TRUE;
break;
case EXPAND: case EXPAND:
if (gtk_tree_view_expand_row(tree_view, path, FALSE)) { if (gtk_tree_view_expand_row(tree_view, path, FALSE)) {
gtk_tree_path_down(path); gtk_tree_path_down(path);
@ -1133,6 +1157,9 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
if (is_valid_path == TRUE) { if (is_valid_path == TRUE) {
gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE); gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
if (need_to_scroll == TRUE) {
gtk_tree_view_scroll_to_cell(tree_view, path, NULL, TRUE, 0.5, 0.0);
}
} }
gtk_tree_path_free(path); gtk_tree_path_free(path);