From d72dbe682c965ee700ed212d2819a3039453f9b9 Mon Sep 17 00:00:00 2001 From: KushalSharmaGit <165495965+KushalSharmaGit@users.noreply.github.com> Date: Mon, 1 Jul 2024 07:46:16 +0530 Subject: [PATCH] fix: ensure exact tag matching with enter key behavior refinement (#7387) Co-authored-by: Peng Xiao --- .../affine/page-properties/tags-inline-editor.tsx | 7 ++++--- .../core/src/modules/tag/entities/tag-list.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx b/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx index 413236a0c3..62357b4825 100644 --- a/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx +++ b/packages/frontend/core/src/components/affine/page-properties/tags-inline-editor.tsx @@ -197,7 +197,8 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { [setOpen, setSelectedTagIds] ); - const exactMatch = useLiveData(tagList.tagByTagValue$(inputValue)); + const match = useLiveData(tagList.tagByTagValue$(inputValue)); + const exactMatch = useLiveData(tagList.excactTagByValue$(inputValue)); const filteredTags = useLiveData( inputValue ? tagList.filterTagsByName$(inputValue) : tagList.tags$ @@ -266,7 +267,7 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { tags.find(tag => tag.id === lastTagId)?.untag(pageId); } }, - [exactMatch, inputValue, onAddTag, onCreateTag, pageId, tagIds, tags] + [inputValue, tagIds, exactMatch, onAddTag, onCreateTag, tags, pageId] ); return ( @@ -320,7 +321,7 @@ export const TagsEditor = ({ pageId, readonly }: TagsEditorProps) => { ); })} - {exactMatch || !inputValue ? null : ( + {match || !inputValue ? null : (
{ return get(this.tags$).filter(tag => @@ -76,4 +82,10 @@ export class TagList extends Entity { return get(this.tags$).find(tag => this.filterFn(get(tag.value$), value)); }); } + + excactTagByValue$(value: string) { + return LiveData.computed(get => { + return get(this.tags$).find(tag => this.findfn(get(tag.value$), value)); + }); + } }