Skip to content

Commit

Permalink
hints: Re-enable nearly all call_hint_function invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Virgil Dupras authored and fanglingsu committed May 6, 2017
1 parent ee115b3 commit fb2c77b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
7 changes: 6 additions & 1 deletion src/ex.c
Expand Up @@ -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) {
Expand Down
55 changes: 25 additions & 30 deletions src/hints.c
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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)) {
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/hints.h
Expand Up @@ -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);
Expand Down

0 comments on commit fb2c77b

Please sign in to comment.