mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-27 14:06:00 +01:00
Delete line to start
Thanks to n0nsense
This commit is contained in:
parent
162ae295b7
commit
eae4e48877
2 changed files with 37 additions and 27 deletions
|
@ -134,6 +134,7 @@ InputbarShortcut inputbar_shortcuts[] = {
|
||||||
{GDK_CONTROL_MASK, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS_GROUP } },
|
{GDK_CONTROL_MASK, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS_GROUP } },
|
||||||
{0, GDK_BackSpace, isc_string_manipulation, { DELETE_LAST_CHAR } },
|
{0, GDK_BackSpace, isc_string_manipulation, { DELETE_LAST_CHAR } },
|
||||||
{GDK_CONTROL_MASK, GDK_h, isc_string_manipulation, { DELETE_LAST_CHAR } },
|
{GDK_CONTROL_MASK, GDK_h, isc_string_manipulation, { DELETE_LAST_CHAR } },
|
||||||
|
{GDK_CONTROL_MASK, GDK_u, isc_string_manipulation, { DELETE_TO_LINE_START } },
|
||||||
{GDK_CONTROL_MASK, GDK_w, isc_string_manipulation, { DELETE_LAST_WORD } },
|
{GDK_CONTROL_MASK, GDK_w, isc_string_manipulation, { DELETE_LAST_WORD } },
|
||||||
{GDK_CONTROL_MASK, GDK_f, isc_string_manipulation, { NEXT_CHAR } },
|
{GDK_CONTROL_MASK, GDK_f, isc_string_manipulation, { NEXT_CHAR } },
|
||||||
{GDK_CONTROL_MASK, GDK_b, isc_string_manipulation, { PREVIOUS_CHAR } },
|
{GDK_CONTROL_MASK, GDK_b, isc_string_manipulation, { PREVIOUS_CHAR } },
|
||||||
|
|
63
zathura.c
63
zathura.c
|
@ -26,7 +26,8 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
|
||||||
PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
|
PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
|
||||||
BACKWARD, ADJUST_BESTFIT, ADJUST_WIDTH, ADJUST_NONE, CONTINUOUS, DELETE_LAST,
|
BACKWARD, ADJUST_BESTFIT, ADJUST_WIDTH, ADJUST_NONE, CONTINUOUS, DELETE_LAST,
|
||||||
ADD_MARKER, EVAL_MARKER, EXPAND, COLLAPSE, SELECT, GOTO_DEFAULT, GOTO_LABELS,
|
ADD_MARKER, EVAL_MARKER, EXPAND, COLLAPSE, SELECT, GOTO_DEFAULT, GOTO_LABELS,
|
||||||
GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR };
|
GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR,
|
||||||
|
DELETE_TO_LINE_START };
|
||||||
|
|
||||||
/* define modes */
|
/* define modes */
|
||||||
#define ALL (1 << 0)
|
#define ALL (1 << 0)
|
||||||
|
@ -2601,38 +2602,46 @@ isc_completion(Argument* argument)
|
||||||
void
|
void
|
||||||
isc_string_manipulation(Argument* argument)
|
isc_string_manipulation(Argument* argument)
|
||||||
{
|
{
|
||||||
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, -1);
|
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, -1);
|
||||||
int length = strlen(input);
|
int length = strlen(input);
|
||||||
int pos = gtk_editable_get_position(GTK_EDITABLE(Zathura.UI.inputbar));
|
int pos = gtk_editable_get_position(GTK_EDITABLE(Zathura.UI.inputbar));
|
||||||
|
int i;
|
||||||
|
|
||||||
if(argument->n == DELETE_LAST_WORD)
|
switch (argument->n) {
|
||||||
{
|
case DELETE_LAST_WORD:
|
||||||
int i = pos - 1;
|
i = pos - 1;
|
||||||
|
|
||||||
if(!pos)
|
if(!pos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* remove trailing spaces */
|
/* remove trailing spaces */
|
||||||
for(; i >= 0 && input[i] == ' '; i--);
|
for(; i >= 0 && input[i] == ' '; i--);
|
||||||
|
|
||||||
/* find the beginning of the word */
|
/* find the beginning of the word */
|
||||||
while((i > 0) && (input[i] != ' ') && (input[i] != '/'))
|
while((i > 0) && (input[i] != ' ') && (input[i] != '/'))
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), i, pos);
|
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), i, pos);
|
||||||
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), i);
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), i);
|
||||||
|
break;
|
||||||
|
case DELETE_LAST_CHAR:
|
||||||
|
if((length - 1) <= 0)
|
||||||
|
isc_abort(NULL);
|
||||||
|
|
||||||
|
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), pos - 1, pos);
|
||||||
|
break;
|
||||||
|
case DELETE_TO_LINE_START:
|
||||||
|
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), 1, pos);
|
||||||
|
break;
|
||||||
|
case NEXT_CHAR:
|
||||||
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), pos + 1);
|
||||||
|
break;
|
||||||
|
case PREVIOUS_CHAR:
|
||||||
|
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), (pos == 0) ? 0 : pos - 1);
|
||||||
|
break;
|
||||||
|
default: /* unreachable */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if(argument->n == DELETE_LAST_CHAR)
|
|
||||||
{
|
|
||||||
if((length - 1) <= 0)
|
|
||||||
isc_abort(NULL);
|
|
||||||
|
|
||||||
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), pos - 1, pos);
|
|
||||||
}
|
|
||||||
else if(argument->n == NEXT_CHAR)
|
|
||||||
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), pos+1);
|
|
||||||
else if(argument->n == PREVIOUS_CHAR)
|
|
||||||
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), (pos == 0) ? 0 : pos - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* command implementation */
|
/* command implementation */
|
||||||
|
|
Loading…
Reference in a new issue