From 471c011f8dffb1db56c26d57f7713baab53e2925 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 1 Jul 2011 14:00:33 +0200 Subject: [PATCH] Support :digits (Closes: #41) Thanks to Serge Guelton for the patch. Applied with some small modifications. --- zathura.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/zathura.c b/zathura.c index 71180aa..09de447 100644 --- a/zathura.c +++ b/zathura.c @@ -4017,6 +4017,24 @@ bcmd_goto(char* buffer, Argument* argument) update_status(); } +gboolean +try_goto(const char* buffer) +{ + char* endptr = NULL; + long page_number = strtol(buffer, &endptr, 10) - 1; + if(*endptr) + /* conversion error */ + return FALSE; + else + { + /* behave like vim: <= 1 => first line, >= #lines => last line */ + page_number = MAX(0, MIN(Zathura.PDF.number_of_pages - 1, page_number)); + set_page(page_number); + update_status(); + return TRUE; + } +} + void bcmd_scroll(char* buffer, Argument* argument) { @@ -4331,8 +4349,11 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data) if(retv) isc_abort(NULL); - if(!succ) - notify(ERROR, "Unknown command."); + if(!succ) { + /* it maybe a goto command */ + if(!try_goto(command)) + notify(ERROR, "Unknown command."); + } Argument arg = { HIDE }; isc_completion(&arg);