how to get selected content in v6

when we use codemirror in v5,we can use doc.getSelection to get the currently selected code,
but how to get currently selected code in codemirror v6?

Something like v.state.sliceDoc(v.state.selection.main.from, v.state.selection.main.to).

thanks,it does work.

for example :