Discussion:
[zathura] [Zathura PATCH 1/2] Make jumping with ^o and ^i more compatible with Vim
Marwan Tanager
2013-06-14 18:15:07 UTC
Permalink
- 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;
--
1.7.10.4
Marwan Tanager
2013-06-14 18:15:08 UTC
Permalink
---
shortcuts.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/shortcuts.c b/shortcuts.c
index cf916dd..9776901 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -721,6 +721,7 @@ sc_jumplist(girara_session_t* session, girara_argument_t* argument,
zathura_t* zathura = session->global.data;
g_return_val_if_fail(argument != NULL, false);
g_return_val_if_fail(zathura->document != NULL, false);
+ g_return_val_if_fail(zathura->jumplist.size != 0, 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;
--
1.7.10.4
Sebastian Ramacher
2013-06-20 18:23:43 UTC
Permalink
Post by Marwan Tanager
+ if (jump == prev_jump) {
+ if (zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD ||
+ zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD) {
I suppose this should be if ((firstline) || (secondline)). Applied with
the additional paranthesis.

Thanks!
--
Sebastian Ramacher
Marwan Tanager
2013-06-21 01:55:56 UTC
Permalink
Post by Sebastian Ramacher
Post by Marwan Tanager
+ if (jump == prev_jump) {
+ if (zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD ||
+ zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD) {
I suppose this should be if ((firstline) || (secondline)). Applied with
the additional paranthesis.
This is not strictly necessary because the '&&' operator has higher precedence
than '||', but regardless, it's safer that way, as well as supressing the
resultant compiler warning.


--
Marwan

Loading...