Is there any method to obtain the selected content in the editor?

Is there any method to obtain the selected content in the editor?
image

@xiaofan thank you for the discussion, given you have an EditorWidget, you can obtain the underlying TextEditor and obtain the selection from it:

For example:

const selection = this.editorManager.currentEditor.editor.selection;

But what if I want to get the string ‘print’? I can only get its position in the editor now, but I cannot get its content. What should I do?

@xiaofan Using the selection that Vince provided, you can get the text from the document:

const editorWidget = this.editorManager.currentEditor;
const selection = editorWidget.editor.selection;
const text = editorWidget.editor.document.getText(selection);

Thanks for your reply.