Forum Academy Marketplace Showcase Pricing Features

Get multiline input value before cursor

Hi guys ! :wave:

I stumbled upon this problem and did not find the solution in the last few days… so you are my last hope.

Here is the problem to solve.

I have a multiline input. The user can click on this multiline input. I want to get the multiline input’s text value that is written before the cursor position of the user.

Let’s see an example, to be clear. If the total text input is the following, with (cursor) the position of the user’s cursor in the multiline input :

“Hello (cursor) world !”

I want the returned value to be: “Hello”

I know I can get the selected text to be returned. I know I can get the cursor position in the text.
But I can’t get the value of the text before the cursor position !

If anyone has some idea on how to do this, it would be greatly appreciated !

Thanks, Anton

An ugly solution I came up with is the following :

  • Using a plugin, insert a special character at the cursor’s position. “[][]]” ← this for example
  • Use the “split by” and use this “[][]]” as your character to split by; then add the “:first item” to get your text, before your cursor value

This topic was automatically closed after 70 days. New replies are no longer allowed.