Updated statusbar string manipulation

This commit is contained in:
Moritz Lipp 2010-06-22 01:57:08 +02:00
parent 1ab25b9112
commit ad5dcd0e70
2 changed files with 35 additions and 20 deletions

View File

@ -123,13 +123,18 @@ Shortcut shortcuts[] = {
InputbarShortcut inputbar_shortcuts[] = { InputbarShortcut inputbar_shortcuts[] = {
/* mask, key, function, argument */ /* mask, key, function, argument */
{0, GDK_Escape, isc_abort, {0} }, {0, GDK_Escape, isc_abort, {0} },
{GDK_CONTROL_MASK, GDK_c, isc_abort, {0} },
{0, GDK_Up, isc_command_history, {0} }, {0, GDK_Up, isc_command_history, {0} },
{0, GDK_Down, isc_command_history, {0} }, {0, GDK_Down, isc_command_history, {0} },
{0, GDK_Tab, isc_completion, { NEXT } }, {0, GDK_Tab, isc_completion, { NEXT } },
{GDK_CONTROL_MASK, GDK_Tab, isc_completion, { NEXT_GROUP } }, {GDK_CONTROL_MASK, GDK_Tab, isc_completion, { NEXT_GROUP } },
{0, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS } }, {0, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS } },
{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 } },
{GDK_CONTROL_MASK, GDK_h, isc_string_manipulation, { DELETE_LAST_CHAR } },
{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_b, isc_string_manipulation, { PREVIOUS_CHAR } },
}; };
/* mouse settings */ /* mouse settings */

View File

@ -21,11 +21,11 @@
/* enums */ /* enums */
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
DELETE_LAST_WORD, DEFAULT, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP, DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP,
ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, BACKWARD, PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
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 }; GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR };
/* define modes */ /* define modes */
#define ALL (1 << 0) #define ALL (1 << 0)
@ -2483,28 +2483,38 @@ 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);
int length = strlen(input);
int pos = gtk_editable_get_position(GTK_EDITABLE(Zathura.UI.inputbar));
if(argument->n == DELETE_LAST_WORD) if(argument->n == DELETE_LAST_WORD)
{ {
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, -1); int i = pos - 1;
int length = strlen(input);
int i = 0;
for(i = length; i > 0; i--) if(!pos)
{ return;
if( (input[i] == ' ') ||
(input[i] == '/') )
{
if(i == (length - 1))
continue;
i = (input[i] == ' ') ? (i - 1) : i; /* remove trailing spaces */
break; for(; i >= 0 && input[i] == ' '; i--);
}
}
notify(DEFAULT, g_strndup(input, i + 1)); /* find the beginning of the word */
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); while((i > 0) && (input[i] != ' ') && (input[i] != '/'))
i--;
gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), i, pos);
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), i);
} }
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 */