-
Notifications
You must be signed in to change notification settings - Fork 260
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
Support quill.format("mention") better for manual mentioning #152
Comments
In case it helps, this is what I've had to do to workaround the issues: newCharacterFromSelection() {
const selection = this.editor.quillEditor.getSelection();
const selectedText = this.editor.quillEditor.getText(
selection.index,
selection.length,
);
// This could be any function that returns an observable
this.charService.newCharacter(selectedText).subscribe((character) => {
// Must focus manually, probably due to focus changing due to modal
this.editor.quillEditor.focus();
// Delete selection, because format("mention") doesn't
this.editor.quillEditor.deleteText(selection.index, selection.length);
this._insertMention({
type: "character",
id: character.id,
value: character.name,
denotationChar: DENOTATIONS.CHARACTER,
});
// Set cursor to after the mention (should be index + 1, but only + 2 worked)
this.editor.quillEditor.setSelection(selection.index + 2, 0);
});
}
_insertMention(data: {
type: string;
id: number;
value: string;
denotationChar: string;
}) {
try {
this.editor.quillEditor.format("mention", {
index: 0,
...data,
});
} catch (e) {
// Have to wrap in try/catch otherwise error can prevent focus/selection/delete working properly
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are two problems when using
quill.format("mention", ...)
:TypeError: wrapper.appendChild is not a function
Other than that, it actually seems to work fine. The first problem can be be worked around by manually deleting text and changing cursor position, and I'm not sure what is breaking due to the error (other than the function not returning anything). But it seems this use case wasn't considered.
Tested with:
Versions (using in Angular 9)
The text was updated successfully, but these errors were encountered: