Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Filter Inline Command List With User Input #6940

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions plugins/text-editor-resources/src/components/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,29 @@ export function inlineCommandsConfig (
): Partial<CompletionOptions> {
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] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using internal text keys as a search condition won't work well. Users will expect the search to work for what they see in the menu so for the interface in english it may poorly work in some cases (where the text doesn't match the key) and for the interface in other languages it won't work at all. Please consider searching by translated texts.

: { ...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)
Expand All @@ -169,6 +184,7 @@ export function inlineCommandsConfig (
element: document.body,
props: {
...props,
query: props.query,
close: () => {
component.destroy()
}
Expand Down