From 29ffe71bc1b0ed6322105c1ebcb565f6793ea81e Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Fri, 23 Jun 2006 04:07:52 +0000 Subject: [PATCH] New actions: kill-word-back, move-backward-word, move-forward-word --- src/bfu/inpfield.c | 37 ++++++++++++++++++++++++++++++ src/config/actions-edit.inc | 3 +++ src/config/kbdbind.c | 3 +++ src/viewer/text/form.c | 45 +++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/src/bfu/inpfield.c b/src/bfu/inpfield.c index 4ee053065..a0b265fb8 100644 --- a/src/bfu/inpfield.c +++ b/src/bfu/inpfield.c @@ -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); diff --git a/src/config/actions-edit.inc b/src/config/actions-edit.inc index f4338cfba..058674bec 100644 --- a/src/config/actions-edit.inc +++ b/src/config/actions-edit.inc @@ -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), diff --git a/src/config/kbdbind.c b/src/config/kbdbind.c index 2c150e5ac..09c7ceb04 100644 --- a/src/config/kbdbind.c +++ b/src/config/kbdbind.c @@ -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 }, diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 23d15c364..dce109fc5 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -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)) {