From: Virgil Dupras Date: Sat, 29 Apr 2017 02:02:03 +0000 (-0400) Subject: hints: Re-enable nearly all call_hint_function invocations X-Git-Url: https://git.owens.tech/rss.xml/rss.xml/git?a=commitdiff_plain;h=fb2c77b2755da7367ebbcbff7ebbb683031d5785;p=vimb.git hints: Re-enable nearly all call_hint_function invocations --- diff --git a/src/ex.c b/src/ex.c index 39cc60b..f558e4c 100644 --- a/src/ex.c +++ b/src/ex.c @@ -241,7 +241,12 @@ VbResult ex_keypress(Client *c, int key) VbResult res; const char *text; - /* TODO delegate call to hint mode if this is active */ + /* delegate call to hint mode if this is active */ + if (c->mode->flags & FLAG_HINTING + && RESULT_COMPLETE == hints_keypress(c, key)) { + + return RESULT_COMPLETE; + } /* process the register */ if (info.phase == PHASE_REG) { diff --git a/src/hints.c b/src/hints.c index 1792120..c5e8346 100644 --- a/src/hints.c +++ b/src/hints.c @@ -45,25 +45,21 @@ static struct { extern struct Vimb vb; -static gboolean call_hints_function(Client *c, const char *func, int count, JSValueRef params[]); +static gboolean call_hints_function(Client *c, const char *func, char* args); static void fire_timeout(Client *c, gboolean on); static gboolean fire_cb(gpointer data); VbResult hints_keypress(Client *c, int key) { - JSValueRef arguments[1]; - if (key == KEY_CR) { hints_fire(c); return RESULT_COMPLETE; } else if (key == CTRL('H')) { fire_timeout(c, false); - arguments[0] = JSValueMakeNull(hints.ctx); - if (call_hints_function(c, "update", 1, arguments)) { - return RESULT_COMPLETE; - } + call_hints_function(c, "update", "null"); + return RESULT_MORE; // continue handling the backspace } else if (key == KEY_TAB) { fire_timeout(c, false); hints_focus_next(c, false); @@ -77,10 +73,8 @@ VbResult hints_keypress(Client *c, int key) } else { fire_timeout(c, true); /* try to handle the key by the javascript */ - /* arguments[0] = js_string_to_ref(hints.ctx, (char[]){key, '\0'}); */ - /* if (call_hints_function(c, "update", 1, arguments)) { */ - /* return RESULT_COMPLETE; */ - /* } */ + call_hints_function(c, "update", (char[]){key, '\0'}); + return RESULT_COMPLETE; } fire_timeout(c, false); @@ -93,7 +87,7 @@ void hints_clear(Client *c) c->mode->flags &= ~FLAG_HINTING; vb_input_set_text(c, ""); - call_hints_function(c, "clear", 0, NULL); + call_hints_function(c, "clear", ""); g_signal_emit_by_name(c->webview, "hovering-over-link", NULL, NULL); @@ -105,9 +99,9 @@ void hints_clear(Client *c) } } -void hints_create(Client *c, const char *input) +void hints_create(Client *c, char *input) { - char *jscode; + char *jsargs; /* check if the input contains a valid hinting prompt */ if (!hints_parse_prompt(input, &hints.mode, &hints.gmode)) { @@ -134,7 +128,7 @@ void hints_create(Client *c, const char *input) hints.promptlen = hints.gmode ? 3 : 2; - jscode = g_strdup_printf("hints.init('%s', %s, %d, '%s', %s, %s);", + jsargs = g_strdup_printf("'%s', %s, %d, '%s', %s, %s", (char[]){hints.mode, '\0'}, hints.gmode ? "true" : "false", MAXIMUM_HINTS, @@ -143,29 +137,26 @@ void hints_create(Client *c, const char *input) GET_BOOL(c, "hint-number-same-length") ? "true" : "false" ); - ext_proxy_eval_script(c, jscode, NULL); - g_free(jscode); + call_hints_function(c, "init", jsargs); + g_free(jsargs); /* if hinting is started there won't be any additional filter given and * we can go out of this function */ return; } - /* JSValueRef arguments[] = {js_string_to_ref(hints.ctx, *(input + hints.promptlen) ? input + hints.promptlen : "")}; */ - /* call_hints_function(c, "filter", 1, arguments); */ + jsargs = *(input + hints.promptlen) ? input + hints.promptlen : ""; + call_hints_function(c, "filter", jsargs); } void hints_focus_next(Client *c, const gboolean back) { - JSValueRef arguments[] = { - JSValueMakeNumber(hints.ctx, back) - }; - call_hints_function(c, "focus", 1, arguments); + call_hints_function(c, "focus", back ? "true" : "false"); } void hints_fire(Client *c) { - call_hints_function(c, "fire", 0, NULL); + call_hints_function(c, "fire", ""); } void hints_follow_link(Client *c, const gboolean back, int count) @@ -187,11 +178,11 @@ void hints_follow_link(Client *c, const gboolean back, int count) void hints_increment_uri(Client *c, int count) { - JSValueRef arguments[] = { - JSValueMakeNumber(hints.ctx, count) - }; + char *jsargs; - call_hints_function(c, "incrementUri", 1, arguments); + jsargs = g_strdup_printf("%d", count); + call_hints_function(c, "incrementUri", jsargs); + g_free(jsargs); } /** @@ -253,9 +244,13 @@ gboolean hints_parse_prompt(const char *prompt, char *mode, gboolean *is_gmode) return res; } -static gboolean call_hints_function(Client *c, const char *func, int count, JSValueRef params[]) +static gboolean call_hints_function(Client *c, const char *func, char* args) { - /* char *value = js_object_call_function(hints.ctx, hints.obj, func, count, params); */ + char *jscode; + + jscode = g_strdup_printf("hints.%s(%s);", func, args); + ext_proxy_eval_script(c, jscode, NULL); + g_free(jscode); char *value = ""; return true; diff --git a/src/hints.h b/src/hints.h index 6821554..1b23e86 100644 --- a/src/hints.h +++ b/src/hints.h @@ -23,7 +23,7 @@ #include "main.h" VbResult hints_keypress(Client *c, int key); -void hints_create(Client *c, const char *input); +void hints_create(Client *c, char *input); void hints_fire(Client *c); void hints_follow_link(Client *c, gboolean back, int count); void hints_increment_uri(Client *c, int count);