在 CKEDITOR 5 中获取 highlighted/selected 文本

Get the highlighted/selected text in CKEDITOR 5

我有我的内联 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);
});

我还有一个按钮,应该可以在 ckeditor

中获取 highlighted/selected 文本
 $("#btnAddTag").click(function (e) {
        e.preventDefault();
        var editor = globalEditor;

        var getText = editor.getSelection().getNative(); //I tried this but the *getSelection* is undefined
 });

有什么建议吗?

已解决问题

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
}