Skip to content

Commit 543bca7

Browse files
committed
Update: Filter command list based on user query text
Signed-off-by: Om Jogani <[email protected]>
1 parent 499ef4d commit 543bca7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugins/text-editor-resources/src/components/extensions.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import textEditor from '@hcengineering/text-editor'
2020
import { type CompletionOptions } from '../Completion'
2121
import MentionList from './MentionList.svelte'
2222
import { SvelteRenderer } from './node-view'
23-
import type { SuggestionKeyDownProps, SuggestionProps } from './extension/suggestion'
23+
import type { SuggestionKeyDownProps, SuggestionOptions, SuggestionProps } from './extension/suggestion'
2424
import InlineCommandsList from './InlineCommandsList.svelte'
2525

2626
export const mInsertTable = [
@@ -141,14 +141,29 @@ export function inlineCommandsConfig (
141141
): Partial<CompletionOptions> {
142142
return {
143143
suggestion: {
144-
items: () => {
145-
return [
144+
items: ({ query }: { query: string }) => {
145+
const items = [
146146
{ id: 'image', label: textEditor.string.Image, icon: view.icon.Image },
147147
{ id: 'table', label: textEditor.string.Table, icon: view.icon.Table2 },
148148
{ id: 'code-block', label: textEditor.string.CodeBlock, icon: view.icon.CodeBlock },
149149
{ id: 'separator-line', label: textEditor.string.SeparatorLine, icon: view.icon.SeparatorLine },
150150
{ id: 'todo-list', label: textEditor.string.TodoList, icon: view.icon.TodoList }
151151
].filter(({ id }) => !excludedCommands.includes(id as InlineCommandId))
152+
153+
// to handle case of `todo-list` and `action-item` being the same
154+
const searchableItems = items.map(item =>
155+
item.id === 'todo-list'
156+
? { ...item, searchLabels: ['action-item', textEditor.string.TodoList] }
157+
: { ...item, searchLabels: [item.label] }
158+
)
159+
160+
const filteredItems = searchableItems.filter(item =>
161+
item.searchLabels.some(label =>
162+
label.toLowerCase().includes(query.toLowerCase())
163+
)
164+
)
165+
166+
return filteredItems.length > 0 ? filteredItems : items
152167
},
153168
command: ({ editor, range, props }: { editor: Editor, range: Range, props: any }) => {
154169
editor.commands.deleteRange(range)
@@ -169,6 +184,7 @@ export function inlineCommandsConfig (
169184
element: document.body,
170185
props: {
171186
...props,
187+
query: props.query,
172188
close: () => {
173189
component.destroy()
174190
}

0 commit comments

Comments
 (0)