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

Add slash command and emoji picker to mail composer #8594

Merged
merged 2 commits into from
Oct 27, 2023

Conversation

hamza221
Copy link
Contributor

@hamza221 hamza221 commented Jul 3, 2023

Closes #8514
image
image

@hamza221 hamza221 added enhancement 3. to review skill:frontend Issues and PRs that require JavaScript/Vue/styling development skills feature:composer labels Jul 3, 2023
@hamza221 hamza221 changed the title Add slash command to mail composer Add slash command and emoji picker to mail composer Jul 14, 2023
@ChristophWurst ChristophWurst requested review from kesselb and removed request for st3iny and GretaD September 14, 2023 06:10
@ChristophWurst
Copy link
Member

Inserting 'any link' always puts the cursor at the start of the message

is it because the focus is lost when the picker shows? Could we get the last cursor position on blur?

@kesselb
Copy link
Contributor

kesselb commented Sep 27, 2023

@hamza221 mind to resolve the conflicts and rebase on main?

@kesselb
Copy link
Contributor

kesselb commented Sep 27, 2023

cursor position after inserting link is nondeterministic

I can reproduce. CKEditor uses an internal structure to represent the content, and therefore it's a bit tricky to insert data or modify the content externally.

this.editorInstance.execute('delete')
this.appendToBodyAtCursor(link)

The approach to delete the last character only works for / and :.
It does not work for /fil or :wav. Especially for emojis, it is quite common to filter the list.

What we actually want is to take the current position, go back to the last slash and replace with the link.
Here is a small poc for the smart picker: #8898

I found your approach connecting Tribute.js and CKEditor very creative, yet I have mixed feelings about it. CKEditor has a mentions plugin https://ckeditor.com/docs/ckeditor5/latest/features/mentions.html and there is also a poc for a slash commands based on it ckeditor/ckeditor5@865c940.

Likely, an implementation based on the mentions plugin will take some time.
On the other hand, Tribute.js is unmaintained as per zurb/tribute#765.

@ChristophWurst
Copy link
Member

CKEditor slash commands need a license #8514 (comment)

@kesselb
Copy link
Contributor

kesselb commented Sep 28, 2023

Slash commands is a premium feature and requires a commercial license.
Mentions are not a premium feature.

My hope was/is that we could implement our slash commands based on the mentions plugin. The CKEditor slash commands is also using the mentions plugin internally. ckeditor/ckeditor5@865c940 is a poc done by a CKEditor developer.

I would prefer an integration with CKEditor based on the mentions plugin, but cannot give you an estimate.
Fine by me to continue with the Tribute.js approach and our small plugin to handle the insertion.

@hamza221 hamza221 requested a review from GretaD October 11, 2023 17:30
@kesselb
Copy link
Contributor

kesselb commented Oct 11, 2023

Cursor position resets after inserting a Link everything else works fine

Can you confirm that it only happens for the first link and the second, third, … work as expected?
That makes it even more weird ;)

@kesselb
Copy link
Contributor

kesselb commented Oct 11, 2023

  • writer.setSelection(itemElement, 'after') in insertItem does not help because the cursor position is correct over there.
  • I cannot reproduce the reset cursor problem with const link = 'https://www.nextcloud.com' instead of the smart picker call. As you suggested, something done by the smart picker let ckeditor reset the cursor position but only once in my testings.

if (eventData.marker === '/') {
getLinkWithPicker(item.id)
.then((link) => {
this.editorInstance.execute('InsertItem', link, '/')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.editorInstance.execute('InsertItem', link, '/')
this.editorInstance.execute('InsertItem', link, '/')
this.editorInstance.editing.view.focus()

Seems to "workaround" the reset cursor issue.

If the reference picker is open window._nc_focus_trap shows three focus traps.
When closing the picker the focus goes back to ckeditor.
I'm still lost what is causing ckeditor to reset the cursor then, especially because we had a selection before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The workaround works 👍

src/ckeditor/smartpicker/InsertItem.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/InsertItem.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/InsertItem.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/InsertItem.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/InsertItem.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/PickerPlugin.js Outdated Show resolved Hide resolved
src/ckeditor/smartpicker/PickerPlugin.js Outdated Show resolved Hide resolved
src/components/TextEditor.vue Outdated Show resolved Hide resolved
src/tests/unit/components/PickerPlugin.vue.spec.js Outdated Show resolved Hide resolved
src/components/TextEditor.vue Outdated Show resolved Hide resolved
@ChristophWurst
Copy link
Member

ChristophWurst commented Oct 20, 2023

  • BUG: Type hello / this is a test and then Enter

I expect the smart picker only to show if I press enter right after the slash

@hamza221
Copy link
Contributor Author

  • BUG: Type hello / this is a test and then Enter

I expect the smart picker only to show if I press enter right after the slash

It's because searchProvider returns 'Any Link' if there's no match which is not useful here.
I added a workaround -> Now the options only show if there's a match so you can still search the options through typing

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

I can't comprehend the CKEditor magic but the feature works flawless now

🚀

@kesselb
Copy link
Contributor

kesselb commented Oct 26, 2023

Possible follow up:

  • Compose new message
  • Insert a file
  • After selecting a file you see a small box for a few seconds.
  • If you click on the box or somewhere else the insert is canceled. I guess that's the default modal click outside logic. It would be nice to not cancel the process on outside click if possible.

@hamza221 hamza221 merged commit 34d3f14 into main Oct 27, 2023
30 of 31 checks passed
@hamza221 hamza221 deleted the enh/CKEditor-slash-commands branch October 27, 2023 11:12
@hamza221
Copy link
Contributor Author

hamza221 commented Oct 27, 2023

@kesselb I'm not sure I understand , Do you mean what's happening in this screen recording?
Screencast from 2023-10-27 17-34-45.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release enhancement feature:composer skill:frontend Issues and PRs that require JavaScript/Vue/styling development skills
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bring CKEditor up to standards with NcRichContenteditable
3 participants