From acf114b2ec446220edacda6dbcdea1ec537d67b1 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 29 Jan 2010 13:42:24 +0100 Subject: [PATCH] Delete last character of the buffer It is now possible to delete the last character of the buffer using the backspace key --- config.def.h | 1 + zathura.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index f6ec94e..ac36f2c 100644 --- a/config.def.h +++ b/config.def.h @@ -70,6 +70,7 @@ Shortcut shortcuts[] = { {0, GDK_N, sc_search, -1, { BACKWARD } }, {0, GDK_a, sc_adjust_window, -1, { ADJUST_BESTFIT } }, {0, GDK_s, sc_adjust_window, -1, { ADJUST_WIDTH } }, + {0, GDK_BackSpace, sc_change_buffer, -1, { DELETE_LAST } }, }; /* inputbar shortcuts */ diff --git a/zathura.c b/zathura.c index d0d7824..c5b78a5 100644 --- a/zathura.c +++ b/zathura.c @@ -26,7 +26,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, BACKWARD, ADJUST_BESTFIT, ADJUST_WIDTH, - CONTINUOUS }; + CONTINUOUS, DELETE_LAST }; /* typedefs */ struct CElement @@ -230,6 +230,7 @@ void* search(void*); /* shortcut declarations */ void sc_abort(Argument*); void sc_adjust_window(Argument*); +void sc_change_buffer(Argument*); void sc_change_mode(Argument*); void sc_focus_inputbar(Argument*); void sc_navigate(Argument*); @@ -884,6 +885,33 @@ sc_adjust_window(Argument* argument) draw(Zathura.PDF.page_number); } +void +sc_change_buffer(Argument* argument) +{ + if(!Zathura.Global.buffer) + return; + + int buffer_length = Zathura.Global.buffer->len; + + if(argument->n == DELETE_LAST) + { + if((buffer_length - 1) == 0) + { + g_string_free(Zathura.Global.buffer, TRUE); + Zathura.Global.buffer = NULL; + gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); + } + else + { + GString* temp = g_string_new_len(Zathura.Global.buffer->str, buffer_length - 1); + g_string_free(Zathura.Global.buffer, TRUE); + Zathura.Global.buffer = temp; + gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str); + } + } + +} + void sc_change_mode(Argument* argument) {