问题
I have my Inline CKeditor
let globalEditor;
InlineEditor.create(document.querySelector("#textarea"), {
toolbar: {
items: ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo']
}
}).then(editor => {
globalEditor = editor;
}).catch(err => {
console.error(err.stack);
});
I also have a button that supposed to be getting the highlighted/selected text inside the ckeditor
$("#btnAddTag").click(function (e) {
e.preventDefault();
var editor = globalEditor;
var getText = editor.getSelection().getNative(); //I tried this but the *getSelection* is undefined
});
Any suggestions?
回答1:
Already fixed the problem
const editor = globalEditor;
const selection = editor.model.document.selection;
const range = selection.getFirstRange();
for (const item of range.getItems()) {
console.log(item.data) //return the selected text
}
来源:https://stackoverflow.com/questions/57196777/get-the-highlighted-selected-text-in-ckeditor-5