I am looking for something similar to CharFromPos() from MFC that returns the text to the left of the editor.
One idea that I had was to get the selectionStart & selectionEnd position and use the substring() function to get the text, however, I've not been successful at getting the selectionStart.
Any ideas? Please share
thanks,
adico
One idea that I had was to get the selectionStart & selectionEnd position and use the substring() function to get the text, however, I've not been successful at getting the selectionStart.
Any ideas? Please share
thanks,
adico

Re: Get text from cursor position
Thanks in advance for your help.
Re: Get text from cursor position
function getCharFromPos(editor) { var sWord = ''; var endPos = setCursorPos(editor); var sText = editor.document.$.body.innerText; while (endPos > 0) { var ch = sText.charAt( endPos ); if (ch == ' ') break; sWord += ch; endPos--; } return sText.substring(endPos, 1+cursorPos.z); } function setCursorPos(editor) { if (!editor) return; var objRange = editor.document.$.selection.createRange(); var sOldRange = objRange.text; var sTempStr = '%$#' //insert the sTempStr where the cursor is at objRange.text = sOldRange + sTempStr; objRange.moveStart('character', (0 - sOldRange.length - sTempStr.length)); //save off the new string with sTempStr var sNewText = editor.document.$.body.innerText; //set the actual text value back to how it was objRange.text = sOldRange; // locate sTempStr and get its position for (var i=0; i <= sNewText.length; i++) { var sTemp = sNewText.substring(i, i + sTempStr.length); if (sTemp == sTempStr) { var curPos = (i - sOldRange.length); return curPos-1; } } return 0; }To use it, simply call getCharFromPos and pass in your current editor.
i.e: var strText = getCharFromPos(myEditor);
I welcome suggestions & feedback.
Thanks,
adico