Skip to content

Commit

Permalink
fixup! fixup! feat: add mention to mail
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Sep 12, 2024
1 parent 90f5225 commit 9cc9dec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 19 additions & 7 deletions src/ckeditor/smartpicker/InsertItemCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`

Check failure on line 41 in src/ckeditor/smartpicker/InsertItemCommand.js

View workflow job for this annotation

GitHub Actions / NPM lint

Trailing spaces not allowed
const anchorTextElement = writer.createText(anchorText)
writer.insert(anchorTextElement, currentPosition)

Check failure on line 44 in src/ckeditor/smartpicker/InsertItemCommand.js

View workflow job for this annotation

GitHub Actions / NPM lint

Trailing spaces not allowed
// Now select the newly inserted anchorText
const anchorRange = editor.model.createRangeOn(anchorTextElement)
editor.model.change(writer => {
editor.model.setSelection(anchorRange)
})

Check failure on line 50 in src/ckeditor/smartpicker/InsertItemCommand.js

View workflow job for this annotation

GitHub Actions / NPM lint

Trailing spaces not allowed
editor.execute('link', mailtoHref )

Check failure on line 51 in src/ckeditor/smartpicker/InsertItemCommand.js

View workflow job for this annotation

GitHub Actions / NPM lint

Multiple spaces found before 'mailtoHref'

Check failure on line 51 in src/ckeditor/smartpicker/InsertItemCommand.js

View workflow job for this annotation

GitHub Actions / NPM lint

There should be no space before this paren
} else {
const itemElement = writer.createElement('paragraph')
writer.insertText(item, itemElement)
editor.model.insertContent(itemElement)
}

return
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default {
QuotePlugin,
PickerPlugin,
Mention,
LinkPlugin,
]
const toolbar = ['undo', 'redo']

Expand All @@ -97,7 +98,6 @@ export default {
BoldPlugin,
ItalicPlugin,
BlockQuotePlugin,
LinkPlugin,
ListStyle,
FontPlugin,
RemoveFormat,
Expand Down Expand Up @@ -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' })
Expand Down

0 comments on commit 9cc9dec

Please sign in to comment.