MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / AutoComplete

Method AutoComplete

neo/framework/EditField.cpp:195–295  ·  view source on GitHub ↗

=============== idEditField::AutoComplete =============== */

Source from the content-addressed store, hash-verified

193===============
194*/
195void idEditField::AutoComplete( void ) {
196 char completionArgString[MAX_EDIT_LINE];
197 idCmdArgs args;
198
199 if ( !autoComplete.valid ) {
200 args.TokenizeString( buffer, false );
201 idStr::Copynz( autoComplete.completionString, args.Argv( 0 ), sizeof( autoComplete.completionString ) );
202 idStr::Copynz( completionArgString, args.Args(), sizeof( completionArgString ) );
203 autoComplete.matchCount = 0;
204 autoComplete.matchIndex = 0;
205 autoComplete.currentMatch[0] = 0;
206
207 if ( strlen( autoComplete.completionString ) == 0 ) {
208 return;
209 }
210
211 globalAutoComplete = autoComplete;
212
213 cmdSystem->CommandCompletion( FindMatches );
214 cvarSystem->CommandCompletion( FindMatches );
215
216 autoComplete = globalAutoComplete;
217
218 if ( autoComplete.matchCount == 0 ) {
219 return; // no matches
220 }
221
222 // when there's only one match or there's an argument
223 if ( autoComplete.matchCount == 1 || completionArgString[0] != '\0' ) {
224
225 /// try completing arguments
226 idStr::Append( autoComplete.completionString, sizeof( autoComplete.completionString ), " " );
227 idStr::Append( autoComplete.completionString, sizeof( autoComplete.completionString ), completionArgString );
228 autoComplete.matchCount = 0;
229
230 globalAutoComplete = autoComplete;
231
232 cmdSystem->ArgCompletion( autoComplete.completionString, FindMatches );
233 cvarSystem->ArgCompletion( autoComplete.completionString, FindMatches );
234
235 autoComplete = globalAutoComplete;
236
237 idStr::snPrintf( buffer, sizeof( buffer ), "%s", autoComplete.currentMatch );
238
239 if ( autoComplete.matchCount == 0 ) {
240 // no argument matches
241 idStr::Append( buffer, sizeof( buffer ), " " );
242 idStr::Append( buffer, sizeof( buffer ), completionArgString );
243 SetCursor( strlen( buffer ) );
244 return;
245 }
246 } else {
247
248 // multiple matches, complete to shortest
249 idStr::snPrintf( buffer, sizeof( buffer ), "%s", autoComplete.currentMatch );
250 if ( strlen( completionArgString ) ) {
251 idStr::Append( buffer, sizeof( buffer ), " " );
252 idStr::Append( buffer, sizeof( buffer ), completionArgString );

Callers 3

KeyDownEventMethod · 0.80
Sys_ConsoleInputFunction · 0.80
InputLineWndProcFunction · 0.80

Calls 6

TokenizeStringMethod · 0.80
ArgvMethod · 0.80
ArgsMethod · 0.80
CommandCompletionMethod · 0.45
ArgCompletionMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected