Marwan Tanager
2013-06-14 18:15:07 UTC
- Allow the user to always start with the very last (or first) jump on the
jumplist when pressing ^o (or ^i), while the jumplist iterator is
pointing to the last (or first) jump, and the document is not currently
at the position of this pointed-to jump. This is instead of jumping
directly to the previous/next jump, and skipping the last/first one.
- Don't jump to the current jump pointed to by the jumplist iterator, if
there is no more next jumps, and the jump direction is FORWARD.
- Don't jump to the current jump pointed to by the jumplist iterator, if
there is no more previous jumps, and the jump direction is BACKWARD.
---
shortcuts.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/shortcuts.c b/shortcuts.c
index 7b70c4a..cf916dd 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -722,24 +722,51 @@ sc_jumplist(girara_session_t* session, girara_argument_t* argument,
g_return_val_if_fail(argument != NULL, false);
g_return_val_if_fail(zathura->document != NULL, false);
+ const double scale = zathura_document_get_scale(zathura->document);
+ double x = gtk_adjustment_get_value(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view))) / scale;
+ double y = gtk_adjustment_get_value(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view))) / scale;
zathura_jump_t* jump = NULL;
+ zathura_jump_t* prev_jump = zathura_jumplist_current(zathura);
+ bool go_to_current = false;
+
+ if (!zathura_jumplist_has_next(zathura) || !zathura_jumplist_has_previous(zathura)) {
+ if (x == prev_jump->x && y == prev_jump->y) {
+ go_to_current = false;
+ } else {
+ go_to_current = true;
+ }
+ }
+
switch(argument->n) {
case FORWARD:
- zathura_jumplist_forward(zathura);
- jump = zathura_jumplist_current(zathura);
+ if (go_to_current == true && zathura_jumplist_has_previous(zathura) == false) {
+ jump = zathura_jumplist_current(zathura);
+ } else {
+ zathura_jumplist_forward(zathura);
+ jump = zathura_jumplist_current(zathura);
+ }
break;
-
case BACKWARD:
- zathura_jumplist_backward(zathura);
- jump = zathura_jumplist_current(zathura);
+ if (go_to_current == true && zathura_jumplist_has_next(zathura) == false) {
+ jump = zathura_jumplist_current(zathura);
+ } else {
+ zathura_jumplist_backward(zathura);
+ jump = zathura_jumplist_current(zathura);
+ }
break;
}
+ if (jump == prev_jump) {
+ if (zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD ||
+ zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD) {
+ jump = NULL;
+ }
+ }
+
if (jump != NULL) {
zathura_document_set_current_page_number(zathura->document, jump->page);
statusbar_page_number_update(zathura);
- const double s = zathura_document_get_scale(zathura->document);
- position_set_delayed(zathura, jump->x * s, jump->y * s);
+ position_set_delayed(zathura, jump->x * scale, jump->y * scale);
}
return false;
jumplist when pressing ^o (or ^i), while the jumplist iterator is
pointing to the last (or first) jump, and the document is not currently
at the position of this pointed-to jump. This is instead of jumping
directly to the previous/next jump, and skipping the last/first one.
- Don't jump to the current jump pointed to by the jumplist iterator, if
there is no more next jumps, and the jump direction is FORWARD.
- Don't jump to the current jump pointed to by the jumplist iterator, if
there is no more previous jumps, and the jump direction is BACKWARD.
---
shortcuts.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/shortcuts.c b/shortcuts.c
index 7b70c4a..cf916dd 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -722,24 +722,51 @@ sc_jumplist(girara_session_t* session, girara_argument_t* argument,
g_return_val_if_fail(argument != NULL, false);
g_return_val_if_fail(zathura->document != NULL, false);
+ const double scale = zathura_document_get_scale(zathura->document);
+ double x = gtk_adjustment_get_value(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view))) / scale;
+ double y = gtk_adjustment_get_value(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view))) / scale;
zathura_jump_t* jump = NULL;
+ zathura_jump_t* prev_jump = zathura_jumplist_current(zathura);
+ bool go_to_current = false;
+
+ if (!zathura_jumplist_has_next(zathura) || !zathura_jumplist_has_previous(zathura)) {
+ if (x == prev_jump->x && y == prev_jump->y) {
+ go_to_current = false;
+ } else {
+ go_to_current = true;
+ }
+ }
+
switch(argument->n) {
case FORWARD:
- zathura_jumplist_forward(zathura);
- jump = zathura_jumplist_current(zathura);
+ if (go_to_current == true && zathura_jumplist_has_previous(zathura) == false) {
+ jump = zathura_jumplist_current(zathura);
+ } else {
+ zathura_jumplist_forward(zathura);
+ jump = zathura_jumplist_current(zathura);
+ }
break;
-
case BACKWARD:
- zathura_jumplist_backward(zathura);
- jump = zathura_jumplist_current(zathura);
+ if (go_to_current == true && zathura_jumplist_has_next(zathura) == false) {
+ jump = zathura_jumplist_current(zathura);
+ } else {
+ zathura_jumplist_backward(zathura);
+ jump = zathura_jumplist_current(zathura);
+ }
break;
}
+ if (jump == prev_jump) {
+ if (zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD ||
+ zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD) {
+ jump = NULL;
+ }
+ }
+
if (jump != NULL) {
zathura_document_set_current_page_number(zathura->document, jump->page);
statusbar_page_number_update(zathura);
- const double s = zathura_document_get_scale(zathura->document);
- position_set_delayed(zathura, jump->x * s, jump->y * s);
+ position_set_delayed(zathura, jump->x * scale, jump->y * scale);
}
return false;
--
1.7.10.4
1.7.10.4