diff --git a/src/components/Suggestion/LinkPicker/LinkPickerList.vue b/src/components/Suggestion/LinkPicker/LinkPickerList.vue index ff059add2af..d08e4eb0add 100644 --- a/src/components/Suggestion/LinkPicker/LinkPickerList.vue +++ b/src/components/Suggestion/LinkPicker/LinkPickerList.vue @@ -25,7 +25,8 @@ @select="(item) => $emit('select', item)"> diff --git a/src/components/Suggestion/LinkPicker/suggestions.js b/src/components/Suggestion/LinkPicker/suggestions.js index 3391c10b169..08e62cf9ddd 100644 --- a/src/components/Suggestion/LinkPicker/suggestions.js +++ b/src/components/Suggestion/LinkPicker/suggestions.js @@ -24,9 +24,37 @@ import LinkPickerList from './LinkPickerList.vue' import { searchProvider, getLinkWithPicker } from '@nextcloud/vue/dist/Components/NcRichText.js' +import menuEntries from './../../Menu/entries.js' + +const suggestGroupFormat = t('text', 'Formatting') +const suggestGroupPicker = t('text', 'Embed') + +const filterOut = (e) => { + return ['undo', 'redo', 'outline', 'emoji-picker'].indexOf(e.key) > -1 +} + +const formattingSuggestions = (query) => { + return [ + ...menuEntries.find(e => e.key === 'headings').children, + ...menuEntries.filter(e => e.action && !filterOut(e)), + ...menuEntries.find(e => e.key === 'callouts').children, + { + ...menuEntries.find(e => e.key === 'emoji-picker'), + action: (command) => command.insertContent(':'), + }, + ].filter(e => e?.label?.toLowerCase?.()?.includes(query.toLowerCase())) + .map(e => ({ ...e, suggestGroup: suggestGroupFormat })) +} + export default () => createSuggestions({ listComponent: LinkPickerList, command: ({ editor, range, props }) => { + if (props.action) { + const commandChain = editor.chain().deleteRange(range) + props.action(commandChain) + commandChain.run() + return + } getLinkWithPicker(props.providerId, true) .then(link => { editor @@ -40,13 +68,17 @@ export default () => createSuggestions({ }) }, items: ({ query }) => { - return searchProvider(query) - .map(p => { - return { - label: p.title, - icon: p.icon_url, - providerId: p.id, - } - }) + return [ + ...formattingSuggestions(query), + ...searchProvider(query) + .map(p => { + return { + suggestGroup: suggestGroupPicker, + label: p.title, + icon: p.icon_url, + providerId: p.id, + } + }), + ] }, }) diff --git a/src/components/Suggestion/SuggestionListWrapper.vue b/src/components/Suggestion/SuggestionListWrapper.vue index 0dc9d6f850d..4ba90fec623 100644 --- a/src/components/Suggestion/SuggestionListWrapper.vue +++ b/src/components/Suggestion/SuggestionListWrapper.vue @@ -23,12 +23,17 @@