Using javascript is it possible to get the text that comes before the cursor?
In the image below I need the following text to be returned: "This is a sample text, sec" or "This is a sample text, first paragraph.
This is a sample text, sec"
It can be the text before the cursor to the beginning of the paragraph or the text before the cursor to the beginning of the document.

Thanks!