Fig Completion Specification - Filter Highlight

· 1 min read

When using Fig, as data is continuously entered, suggestions are continuously filtered and highlighted. Actual testing and analysis revealed the highlighting logic.

Logic

  1. While generating the completion list, calculate N characters from current input command cursor to start matching, defined as charactersToDrop=N
  2. Split N characters into character array, each character performs match highlighting using lazy matching
  3. When user presses enter, terminal first deletes N characters, then writes the matched completion value
  4. User presses enter to select suggestion

Example

Input cd ar, charactersToDrop=2

Each character performs matching. After ‘a’ matches, ‘r’ continues to match, but ‘r’ must match after ‘a’

https://static.1991421.cn/2024/2024-01-15-211931.jpeg

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover