I have a textarea where text will be typed. This text may contain some specific fields (type variables, which will be replaced later). I need to know how to insert these "variables" in the specific location where I need them, for example where the mouse cursor was, since all the examples I have seen so far only include at the end of the text.
An example of how it should work:
" [customer_name] is registered to the system from [dataCadastro] "
The words in bold would be the "variables". You need to get the last mouse position because the user can choose where to insert the fields, which simplifies for him.
Additional information: textarea contains rich text (CKEditor).
As the image below, the user selects the "group" (eg: personal data, company data, vehicle data, etc.) and then the combo "fields" and grouped by group (eg: personal data = > fields: name, age, address, date of birth, etc.). When selecting an item in combo "fields", this item will be added in the textarea, exactly at the last mouse location, which can be either at the end of the field or in the middle of the text.