Skip to content

Commit

Permalink
tag suggestions should be case insensitive (#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebykat committed Feb 13, 2020
1 parent 07e16ee commit 2f33deb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/tag-suggestions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const filterTags = (tags: T.TagEntity[], query: string) => {
// but without knowing where the cursor is it's maybe the best we can do
const tagTerm = query
.trim()
.toLowerCase()
.split(' ')
.pop();

Expand All @@ -112,8 +113,9 @@ export const filterTags = (tags: T.TagEntity[], query: string) => {
const term = isPrefixMatch ? tagTerm.slice(4) : tagTerm;

const matcher: (tag: T.TagEntity) => boolean = isPrefixMatch
? ({ data: { name } }) => name !== term && name.startsWith(term)
: ({ data: { name } }) => name.includes(term);
? ({ data: { name } }) =>
name.toLowerCase() !== term && name.toLowerCase().startsWith(term)
: ({ data: { name } }) => name.toLowerCase().includes(term);

return filterAtMost(tags, matcher, 5);
};
Expand Down
5 changes: 5 additions & 0 deletions lib/tag-suggestions/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ it('finds mid-tag matches', () => {
expect(filterTags(infixen, 'code')).toEqual(infixen);
});

it('finds case insensitive matches', () => {
expect(filterTags(animals, 'Cat')).toEqual(['cat'].map(t));
expect(filterTags(animals, 'OWL')).toEqual(['owl'].map(t));
});

it('uses the last space-separated segment in the query for search', () => {
expect(filterTags(infixen, 'code bug')).toEqual([]);
expect(filterTags(infixen, 'bug code')).toEqual(infixen);
Expand Down

0 comments on commit 2f33deb

Please sign in to comment.