diff --git a/src/ckeditor/smartpicker/InsertItemCommand.js b/src/ckeditor/smartpicker/InsertItemCommand.js index 6539bb83f2..5ee1862dc3 100644 --- a/src/ckeditor/smartpicker/InsertItemCommand.js +++ b/src/ckeditor/smartpicker/InsertItemCommand.js @@ -19,29 +19,41 @@ export default class InsertItemCommand extends Command { // @TODO Add error to handle such a situation in the callback return } - const range = editor.model.createRange( currentPosition.getShiftedBy(-5), currentPosition, ) - // Iterate over all items in this range: const walker = range.getWalker({ shallow: false, direction: 'backward' }) for (const value of walker) { if (value.type === 'text' && value.item.data.includes(trigger)) { writer.remove(value.item) - const text = value.item.data const lastSlash = text.lastIndexOf(trigger) - const textElement = writer.createElement('paragraph') writer.insertText(text.substring(0, lastSlash), textElement) editor.model.insertContent(textElement) - const itemElement = writer.createElement('paragraph') - writer.insertText(item, itemElement) - editor.model.insertContent(itemElement) + if (trigger === '@') { + const mailtoHref = `mailto:${item.email}` + const anchorText = `@${item.label}` + + const anchorTextElement = writer.createText(anchorText) + writer.insert(anchorTextElement, currentPosition) + + // Now select the newly inserted anchorText + const anchorRange = editor.model.createRangeOn(anchorTextElement) + editor.model.change(writer => { + editor.model.setSelection(anchorRange) + }) + + editor.execute('link', mailtoHref ) + } else { + const itemElement = writer.createElement('paragraph') + writer.insertText(item, itemElement) + editor.model.insertContent(itemElement) + } return } diff --git a/src/components/TextEditor.vue b/src/components/TextEditor.vue index 18f713970c..bc9ce07300 100644 --- a/src/components/TextEditor.vue +++ b/src/components/TextEditor.vue @@ -87,6 +87,7 @@ export default { QuotePlugin, PickerPlugin, Mention, + LinkPlugin, ] const toolbar = ['undo', 'redo'] @@ -97,7 +98,6 @@ export default { BoldPlugin, ItalicPlugin, BlockQuotePlugin, - LinkPlugin, ListStyle, FontPlugin, RemoveFormat, @@ -338,7 +338,7 @@ export default { }) } if (eventData.marker === '@') { - this.editorInstance.execute('insertItem', `@${item.label}`, '@') + this.editorInstance.execute('insertItem', { email: item.email[0], label: item.label }, '@') this.$emit('mention', { email: item.email[0], label: item.label }) } }, { priority: 'high' })