+ if( vg_ui.focused_control_type != k_ui_control_textbox ||
+ vg_ui.textbuf != vg_console.input )
+ return;
+
+ vg_console.suggestion_count = 0;
+ vg_console.suggestion_select = -1;
+ vg_console.suggestion_maxlen = 0;
+
+ /*
+ * - must be typing something
+ * - must be at the end
+ * - prev char must not be a whitespace
+ * - cursors should match
+ */
+
+ if( vg_ui.textbox.cursor_pos == 0 ) return;
+ if( vg_ui.textbox.cursor_pos != vg_ui.textbox.cursor_user ) return;
+ if( vg_console.input[ vg_ui.textbox.cursor_pos ] != '\0' ) return;
+
+ if( (vg_console.input[ vg_ui.textbox.cursor_pos -1 ] == ' ') ||
+ (vg_console.input[ vg_ui.textbox.cursor_pos -1 ] == '\t') )
+ return;
+
+ char temp[128];
+ const char *args[8];
+
+ int token_count = vg_console_tokenize( vg_console.input, temp, args );
+ if( !token_count ) return;
+ vg_console.suggestion_pastepos = args[token_count-1]-temp;
+
+ /* Score all our commands and cvars */
+ if( token_count == 1 ){
+ for( int i=0; i<vg_console.var_count; i++ ){
+ vg_var *cvar = &vg_console.vars[i];
+ console_suggest_score_text( cvar->name, args[0], 1 );
+ }
+
+ for( int i=0; i<vg_console.function_count; i++ ){
+ vg_cmd *cmd = &vg_console.functions[i];
+ console_suggest_score_text( cmd->name, args[0], 1 );
+ }
+ }
+ else{
+ vg_cmd *cmd = vg_console_match_cmd( args[0] );
+ vg_var *var = vg_console_match_var( args[0] );
+
+ assert( !( cmd && var ) );
+
+ if( cmd )
+ if( cmd->poll_suggest )
+ cmd->poll_suggest( token_count-1, &args[1] );
+ }
+
+ /* some post processing */
+ for( int i=0; i<vg_console.suggestion_count; i++ ){
+ vg_console.suggestion_maxlen = VG_MAX( vg_console.suggestion_maxlen,
+ vg_console.suggestions[i].len );
+
+ if( vg_console.suggestions[i].lev_score <
+ vg_console.suggestions[0].lev_score/2 )
+ {
+ vg_console.suggestion_count = i;
+ return;
+ }
+ }