From: Daniel Carl Date: Mon, 4 Nov 2013 19:47:17 +0000 (+0100) Subject: Hold current prompt chars. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=884de8bea9109cb3ab88bd280c93643628816089;p=vimb.git Hold current prompt chars. This allows to handle the command mode command right and to not remove chars from prompts like ';o'. --- diff --git a/src/ex.c b/src/ex.c index 567b5c5..e771ff2 100644 --- a/src/ex.c +++ b/src/ex.c @@ -205,8 +205,6 @@ void ex_leave(void) */ VbResult ex_keypress(int key) { - /* TODO allow to get the right prompt like ':', '/', ';o', ... */ - char *prompt = ":"; GtkTextIter start, end; GtkTextBuffer *buffer = vb.gui.buffer; GtkTextMark *mark; @@ -267,7 +265,7 @@ VbResult ex_keypress(int key) case CTRL('B'): /* move the cursor direct behind the prompt */ - gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(prompt)); + gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt)); gtk_text_buffer_place_cursor(buffer, &start); break; @@ -281,7 +279,7 @@ VbResult ex_keypress(int key) /* remove everythings between cursor and prompt */ mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &end, mark); - gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(prompt)); + gtk_text_buffer_get_iter_at_offset(buffer, &start, strlen(vb.state.prompt)); gtk_text_buffer_delete(buffer, &start, &end); break; diff --git a/src/history.c b/src/history.c index 0221f24..622eaea 100644 --- a/src/history.c +++ b/src/history.c @@ -65,7 +65,6 @@ void history_cleanup(void) /** * Write a new history entry to the end of history file. - * TODO identify the history by the promt char */ void history_add(HistoryType type, const char *value, const char *additional) { diff --git a/src/main.h b/src/main.h index 7b65589..0cf1d77 100644 --- a/src/main.h +++ b/src/main.h @@ -269,7 +269,9 @@ typedef struct { gboolean is_inspecting; GList *downloads; gboolean processed_key; - char *title; /* holds the window title */ + char *title; /* holds the window title */ +#define PROMPT_SIZE 3 + char prompt[PROMPT_SIZE]; /* current prompt ':', ';o', '/' */ } State; typedef struct { diff --git a/src/mode.c b/src/mode.c index ebf2969..8579be6 100644 --- a/src/mode.c +++ b/src/mode.c @@ -93,6 +93,29 @@ void mode_enter(char id) vb_update_statusbar(); } +/** + * Set the prompt chars and switch to new mode. + * + * @id: Mode id. + * @prompt: Prompt string to set as current promt. + * @print_prompt: Indicates if the new set prompt should be put into inputbox + * after switching the mode. + */ +void mode_enter_promt(char id, const char *prompt, gboolean print_prompt) +{ + /* set the prompt to be accessible in mode_enter */ + strncpy(vb.state.prompt, prompt, PROMPT_SIZE - 1); + vb.state.prompt[PROMPT_SIZE - 1] = '\0'; + + mode_enter(id); + + if (print_prompt) { + /* set it after the mode was entered so that the modes input change + * event listener could grep the new prompt */ + vb_set_input_text(vb.state.prompt); + } +} + VbResult mode_handle_key(int key) { VbResult res; diff --git a/src/mode.h b/src/mode.h index 4040f42..2e3fc33 100644 --- a/src/mode.h +++ b/src/mode.h @@ -28,6 +28,7 @@ void mode_cleanup(void); void mode_add(char id, ModeTransitionFunc enter, ModeTransitionFunc leave, ModeKeyFunc keypress, ModeInputChangedFunc input_changed); void mode_enter(char id); +void mode_enter_promt(char id, const char *prompt, gboolean print_prompt); VbResult mode_handle_key(int key); gboolean mode_input_focusin(GtkWidget *widget, GdkEventFocus *event, gpointer data); gboolean mode_input_focusout(GtkWidget *widget, GdkEventFocus *event, gpointer data); diff --git a/src/normal.c b/src/normal.c index bca27e0..9de67b9 100644 --- a/src/normal.c +++ b/src/normal.c @@ -224,7 +224,6 @@ void normal_enter(void) */ void normal_leave(void) { - /* TODO clean those only if they where active */ command_search(&((Arg){0})); } @@ -392,14 +391,13 @@ static VbResult normal_descent(const NormalCmdInfo *info) static VbResult normal_ex(const NormalCmdInfo *info) { - mode_enter('c'); if (info->cmd == 'F') { - vb_set_input_text(";t"); + mode_enter_promt('c', ";t", true); } else if (info->cmd == 'f') { - vb_set_input_text(";o"); + mode_enter_promt('c', ";o", true); } else { char prompt[2] = {info->cmd, '\0'}; - vb_set_input_text(prompt); + mode_enter_promt('c', prompt, true); } return RESULT_COMPLETE; @@ -460,8 +458,7 @@ static VbResult normal_hint(const NormalCmdInfo *info) return RESULT_ERROR; } - mode_enter('c'); - vb_set_input_text(prompt); + mode_enter_promt('c', prompt, true); return RESULT_COMPLETE; } @@ -474,7 +471,7 @@ static VbResult normal_input_open(const NormalCmdInfo *info) } /* switch mode after setting the input text to not trigger the * commands modes input change handler */ - mode_enter('c'); + mode_enter_promt('c', ":", false); return RESULT_COMPLETE; } diff --git a/src/setting.c b/src/setting.c index 77e4bcb..dfc2700 100644 --- a/src/setting.c +++ b/src/setting.c @@ -235,7 +235,6 @@ gboolean setting_fill_completion(GtkListStore *store, const char *input) } } } - /* TODO sort the store model */ g_list_free(src); return found;