Get Cursor position in Text Area Component

you'll need to put a domId on your textfield

	#make the propName the key to write too in the view.custom 
	propName = "selectedIndex"
	code =  """<img style='display:none' src='/favicon.ico' onload=\"
		const view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == this.parentNode.parentNode.parentNode.getAttributeNode('data-component-path').value.split('.')[0]).value; 
		const table = document.getElementById('"""+value+"""');
		function getSelected(){
							const selectedIndex = document.getElementById('"""+value+"""').selectionStart;
							view.custom.write('"""+propName+"""',selectedIndex);
						};			
		table.onclick = getSelected;
		table.onkeyup = getSelected;				
	\"></img>""".replace("\n", "").replace("\t", "")
	return code
Summary

[ { "type": "ia.display.markdown", "version": 0, "props": { "style": { "flex": "--neutral-40" }, "markdown": { "escapeHtml": false } }, "meta": { "name": "Markdown" }, "position": { "x": 166, "y": 290, "height": 200, "width": 200 }, "custom": {}, "propConfig": { "props.source": { "binding": { "type": "expr", "config": { "expression": "{../TextArea.meta.domId}" }, "transforms": [ { "code": "\t#make the propName the key to write too in the view.custom \n\tpropName = \"selectedIndex\"\n\tcode = \"\"\"<img style='display:none' src='/favicon.ico' onload=\\\"\n\t\tconst view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == this.parentNode.parentNode.parentNode.getAttributeNode('data-component-path').value.split('.')[0]).value; \n\t\tconst table = document.getElementById('\"\"\"+value+\"\"\"');\n\t\tfunction getSelected(){\n\t\t\t\t\t\t\tconst selectedIndex = document.getElementById('\"\"\"+value+\"\"\"').selectionStart;\n\t\t\t\t\t\t\tview.custom.write('\"\"\"+propName+\"\"\"',selectedIndex);\n\t\t\t\t\t\t};\t\t\t\n\t\ttable.onclick = getSelected;\n\t\ttable.onkeyup = getSelected;\t\t\t\t\n\t\\\"></img>\"\"\".replace(\"\\n\", \"\").replace(\"\\t\", \"\")\n\treturn code\n\t", "type": "script" } ] } } } } ]

2 Likes