1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

New actions: kill-word-back, move-backward-word, move-forward-word

This commit is contained in:
Miciah Dashiel Butler Masters 2006-06-23 04:07:52 +00:00 committed by Miciah Dashiel Butler Masters
parent 40a0152ed3
commit 29ffe71bc1
4 changed files with 88 additions and 0 deletions

View File

@ -484,6 +484,43 @@ kbd_field(struct dialog_data *dlg_data, struct widget_data *widget_data)
widget_data->cdata[widget_data->info.field.cpos] = 0;
goto display_field;
case ACT_EDIT_KILL_WORD_BACK:
{
int cdata_len = strlen(widget_data->cdata);
int start = widget_data->info.field.cpos;
while (start > 0 && isspace(widget_data->cdata[start - 1]))
--start;
while (start > 0 && !isspace(widget_data->cdata[start - 1]))
--start;
memmove(widget_data->cdata + start,
widget_data->cdata + widget_data->info.field.cpos,
cdata_len - widget_data->info.field.cpos + 1);
widget_data->info.field.cpos = start;
goto display_field;
}
case ACT_EDIT_MOVE_BACKWARD_WORD:
while (widget_data->info.field.cpos > 0 && isspace(widget_data->cdata[widget_data->info.field.cpos - 1]))
--widget_data->info.field.cpos;
while (widget_data->info.field.cpos > 0 && !isspace(widget_data->cdata[widget_data->info.field.cpos - 1]))
--widget_data->info.field.cpos;
goto display_field;
case ACT_EDIT_MOVE_FORWARD_WORD:
while (isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
while (widget_data->cdata[widget_data->info.field.cpos] && !isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
while (isspace(widget_data->cdata[widget_data->info.field.cpos]))
++widget_data->info.field.cpos;
goto display_field;
case ACT_EDIT_COPY_CLIPBOARD:
/* Copy to clipboard */
set_clipboard_text(widget_data->cdata);

View File

@ -20,7 +20,10 @@ ACTION_(EDIT, "enter", ENTER, N__("Follow the current link"), 0),
ACTION_(EDIT, "home", HOME, N__("Go to the start of the page/line"), 0),
ACTION_(EDIT, "kill-to-bol", KILL_TO_BOL, N__("Delete to beginning of line"), 0),
ACTION_(EDIT, "kill-to-eol", KILL_TO_EOL, N__("Delete to end of line"), 0),
ACTION_(EDIT, "kill-word-back", KILL_WORD_BACK, N__("Delete backwards to start of word"), 0),
ACTION_(EDIT, "left", LEFT, N__("Move the cursor left"), 0),
ACTION_(EDIT, "move-backward-word", MOVE_BACKWARD_WORD, N__("Move cursor before current word"), 0),
ACTION_(EDIT, "move-forward-word", MOVE_FORWARD_WORD, N__("Move cursor after current word"), 0),
ACTION_(EDIT, "next-item", NEXT_ITEM, N__("Move to the next item"), 0),
ACTION_(EDIT, "open-external", OPEN_EXTERNAL, N__("Open in external editor"), ACTION_RESTRICT_ANONYMOUS),
ACTION_(EDIT, "paste-clipboard", PASTE_CLIPBOARD, N__("Paste text from the clipboard"), 0),

View File

@ -688,8 +688,10 @@ static struct default_kb default_edit_keymap[] = {
{ { '<', KBD_MOD_ALT }, ACT_EDIT_BEGINNING_OF_BUFFER },
{ { '>', KBD_MOD_ALT }, ACT_EDIT_END_OF_BUFFER },
{ { 'A', KBD_MOD_CTRL }, ACT_EDIT_HOME },
{ { 'b', KBD_MOD_ALT }, ACT_EDIT_MOVE_BACKWARD_WORD },
{ { 'D', KBD_MOD_CTRL }, ACT_EDIT_DELETE },
{ { 'E', KBD_MOD_CTRL }, ACT_EDIT_END },
{ { 'f', KBD_MOD_ALT }, ACT_EDIT_MOVE_FORWARD_WORD },
{ { 'H', KBD_MOD_CTRL }, ACT_EDIT_BACKSPACE },
{ { 'K', KBD_MOD_CTRL }, ACT_EDIT_KILL_TO_EOL },
{ { 'L', KBD_MOD_CTRL }, ACT_EDIT_REDRAW },
@ -701,6 +703,7 @@ static struct default_kb default_edit_keymap[] = {
{ { 'V', KBD_MOD_CTRL }, ACT_EDIT_PASTE_CLIPBOARD },
{ { 'W', KBD_MOD_CTRL }, ACT_EDIT_AUTO_COMPLETE },
{ { 'X', KBD_MOD_CTRL }, ACT_EDIT_CUT_CLIPBOARD },
{ { KBD_BS, KBD_MOD_ALT }, ACT_EDIT_KILL_WORD_BACK },
{ { KBD_BS, KBD_MOD_NONE }, ACT_EDIT_BACKSPACE },
{ { KBD_DEL, KBD_MOD_NONE }, ACT_EDIT_DELETE },
{ { KBD_DOWN, KBD_MOD_NONE }, ACT_EDIT_DOWN },

View File

@ -1392,6 +1392,51 @@ field_op(struct session *ses, struct document_view *doc_view,
memmove(fs->value + fs->state, text, strlen(text) + 1);
break;
case ACT_EDIT_KILL_WORD_BACK:
if (form_field_is_readonly(fc)) {
status = FRAME_EVENT_IGNORED;
break;
}
if (fs->state <= 0) {
status = FRAME_EVENT_OK;
break;
}
text = &fs->value[fs->state];
while (text > fs->value && isspace(*(text - 1)))
--text;
while (text > fs->value && !isspace(*(text - 1)))
--text;
if (*text == ASCII_LF
&& text != &fs->value[fs->state - 1])
text++;
length = strlen(fs->value + fs->state) + 1;
memmove(text, fs->value + fs->state, length);
fs->state = (int) (text - fs->value);
break;
case ACT_EDIT_MOVE_BACKWARD_WORD:
while (fs->state > 0
&& isspace(fs->value[fs->state - 1]))
--fs->state;
while (fs->state > 0
&& !isspace(fs->value[fs->state - 1]))
--fs->state;
break;
case ACT_EDIT_MOVE_FORWARD_WORD:
while (isspace(fs->value[fs->state]))
++fs->state;
while (fs->value[fs->state]
&& !isspace(fs->value[fs->state]))
++fs->state;
while (isspace(fs->value[fs->state]))
++fs->state;
break;
case ACT_EDIT_AUTO_COMPLETE:
if (fc->type != FC_FILE
|| form_field_is_readonly(fc)) {