From 543bca794f87e7e88814a6b0619979c3ae5f8ce2 Mon Sep 17 00:00:00 2001 From: omjogani Date: Tue, 15 Oct 2024 16:33:14 +0530 Subject: [PATCH 1/2] Update: Filter command list based on user query text Signed-off-by: Om Jogani --- .../src/components/extensions.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/text-editor-resources/src/components/extensions.ts b/plugins/text-editor-resources/src/components/extensions.ts index 8eada21dbf..8aa0edecef 100644 --- a/plugins/text-editor-resources/src/components/extensions.ts +++ b/plugins/text-editor-resources/src/components/extensions.ts @@ -20,7 +20,7 @@ import textEditor from '@hcengineering/text-editor' import { type CompletionOptions } from '../Completion' import MentionList from './MentionList.svelte' import { SvelteRenderer } from './node-view' -import type { SuggestionKeyDownProps, SuggestionProps } from './extension/suggestion' +import type { SuggestionKeyDownProps, SuggestionOptions, SuggestionProps } from './extension/suggestion' import InlineCommandsList from './InlineCommandsList.svelte' export const mInsertTable = [ @@ -141,14 +141,29 @@ export function inlineCommandsConfig ( ): Partial { return { suggestion: { - items: () => { - return [ + items: ({ query }: { query: string }) => { + const items = [ { id: 'image', label: textEditor.string.Image, icon: view.icon.Image }, { id: 'table', label: textEditor.string.Table, icon: view.icon.Table2 }, { id: 'code-block', label: textEditor.string.CodeBlock, icon: view.icon.CodeBlock }, { id: 'separator-line', label: textEditor.string.SeparatorLine, icon: view.icon.SeparatorLine }, { id: 'todo-list', label: textEditor.string.TodoList, icon: view.icon.TodoList } ].filter(({ id }) => !excludedCommands.includes(id as InlineCommandId)) + + // to handle case of `todo-list` and `action-item` being the same + const searchableItems = items.map(item => + item.id === 'todo-list' + ? { ...item, searchLabels: ['action-item', textEditor.string.TodoList] } + : { ...item, searchLabels: [item.label] } + ) + + const filteredItems = searchableItems.filter(item => + item.searchLabels.some(label => + label.toLowerCase().includes(query.toLowerCase()) + ) + ) + + return filteredItems.length > 0 ? filteredItems : items }, command: ({ editor, range, props }: { editor: Editor, range: Range, props: any }) => { editor.commands.deleteRange(range) @@ -169,6 +184,7 @@ export function inlineCommandsConfig ( element: document.body, props: { ...props, + query: props.query, close: () => { component.destroy() } From 3bf06bd7fe2f4e5d63d9ab4b6b92e76fabc7469b Mon Sep 17 00:00:00 2001 From: omjogani Date: Tue, 15 Oct 2024 16:36:19 +0530 Subject: [PATCH 2/2] Update: Remove Unused imports Signed-off-by: omjogani --- plugins/text-editor-resources/src/components/extensions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/text-editor-resources/src/components/extensions.ts b/plugins/text-editor-resources/src/components/extensions.ts index 8aa0edecef..8f273b99ce 100644 --- a/plugins/text-editor-resources/src/components/extensions.ts +++ b/plugins/text-editor-resources/src/components/extensions.ts @@ -20,7 +20,7 @@ import textEditor from '@hcengineering/text-editor' import { type CompletionOptions } from '../Completion' import MentionList from './MentionList.svelte' import { SvelteRenderer } from './node-view' -import type { SuggestionKeyDownProps, SuggestionOptions, SuggestionProps } from './extension/suggestion' +import type { SuggestionKeyDownProps, SuggestionProps } from './extension/suggestion' import InlineCommandsList from './InlineCommandsList.svelte' export const mInsertTable = [