Skip to content

Commit

Permalink
feat(editor): Make expression autocomplete search case-insensitive (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
elsmr authored Jul 11, 2024
1 parent 8171d75 commit cde6fe9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ describe('Resolution-based completions', () => {
Object.keys(object).length + extensions({ typeName: 'object' }).length,
);
});

test('should return case-insensitive completions', () => {
vi.spyOn(workflowHelpers, 'resolveParameter').mockReturnValueOnce('abc');

const result = completions('{{ "abc".tolowerca| }}');
expect(result).toHaveLength(1);
expect(result?.at(0)).toEqual(expect.objectContaining({ label: 'toLowerCase()' }));
});
});

describe('indexed access completions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function datatypeCompletions(context: CompletionContext): CompletionResul
}

if (tail !== '') {
options = options.filter((o) => prefixMatch(o.label, tail) && o.label !== tail);
options = options.filter((o) => prefixMatch(o.label, tail));
}

let from = word.to - tail.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function longestCommonPrefix(...strings: string[]) {
}

export const prefixMatch = (first: string, second: string) =>
first.startsWith(second) && first !== second;
first.toLocaleLowerCase().startsWith(second.toLocaleLowerCase()) && first !== second;

export const isPseudoParam = (candidate: string) => {
const PSEUDO_PARAMS = ['notice']; // user input disallowed
Expand Down

0 comments on commit cde6fe9

Please sign in to comment.