MCPcopy Create free account
hub / github.com/SplootCode/splootcode / prefixMatch

Method prefixMatch

packages/editor/src/components/insert_box.tsx:399–429  ·  view source on GitHub ↗
(userInput: string, prefix: string, remainder: string)

Source from the content-addressed store, hash-verified

397 }
398
399 async prefixMatch(userInput: string, prefix: string, remainder: string): Promise<RenderedSuggestion> {
400 prefix = prefix.trim()
401 if (prefix.length === userInput.length) {
402 return null
403 }
404 userInput = userInput.trim()
405 const prefixNoSpaces = prefix.replace(/\s/g, '')
406
407 const { staticSuggestions, staticSuggestionKeys, autocompleters } = this.state
408 const suggestions = await filterSuggestions(staticSuggestions, staticSuggestionKeys, autocompleters, prefix)
409 if (suggestions.length === 0) {
410 return null
411 }
412 // Check this isn't the prefix of any of the next 3 suggestions
413 const lim = Math.min(3, suggestions.length)
414 let exactMatch = null
415 let prefixMatch = false
416 for (let i = 0; i < lim; i++) {
417 const suggestion = suggestions[i]
418 if (!exactMatch && (suggestion.isExactMatch(prefix) || suggestion.isExactMatch(prefixNoSpaces))) {
419 exactMatch = suggestion
420 } else if (suggestion.isPrefixMatch(userInput)) {
421 prefixMatch = true
422 }
423 }
424 if (exactMatch && !prefixMatch) {
425 return exactMatch
426 }
427
428 return null
429 }
430
431 async handleEarlyInsert(userInput: string): Promise<string> {
432 if (userInput.length < 2) {

Callers 1

handleEarlyInsertMethod · 0.95

Calls 4

filterSuggestionsFunction · 0.85
trimMethod · 0.80
isExactMatchMethod · 0.80
isPrefixMatchMethod · 0.80

Tested by

no test coverage detected