<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField)</title>
	<atom:link href="http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/</link>
	<description>flex developers web corner</description>
	<lastBuildDate>Wed, 18 Jan 2012 13:28:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: hayamaroom (葉山)</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-1924</link>
		<dc:creator>hayamaroom (葉山)</dc:creator>
		<pubDate>Wed, 23 Jun 2010 15:05:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-1924</guid>
		<description>說 http://tinyurl.com/2wa72q FIND CURSOR POSITION IN A HTMLTEXT OBJECT (RICHTEXTEDITOR, TEXTAREA, TEXTFIELD) http://plurk.com/p/5ybn7s</description>
		<content:encoded><![CDATA[<p>說 <a href="http://tinyurl.com/2wa72q" rel="nofollow">http://tinyurl.com/2wa72q</a> FIND CURSOR POSITION IN A HTMLTEXT OBJECT (RICHTEXTEDITOR, TEXTAREA, TEXTFIELD) <a href="http://plurk.com/p/5ybn7s" rel="nofollow">http://plurk.com/p/5ybn7s</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mooska</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-103</link>
		<dc:creator>mooska</dc:creator>
		<pubDate>Tue, 08 Apr 2008 09:25:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-103</guid>
		<description>Well, site removed a bit from regexp (it should find closed tags) and I havent test it much ;) as I needed this fast, but the way seems ok.</description>
		<content:encoded><![CDATA[<p>Well, site removed a bit from regexp (it should find closed tags) and I havent test it much <img src='http://www.flexer.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  as I needed this fast, but the way seems ok.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-101</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Tue, 08 Apr 2008 06:45:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-101</guid>
		<description>Thanks mooska! Great approach... I&#039;ll post you&#039;re comment also in the second part of this series.</description>
		<content:encoded><![CDATA[<p>Thanks mooska! Great approach&#8230; I&#8217;ll post you&#8217;re comment also in the second part of this series.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mooska</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-100</link>
		<dc:creator>mooska</dc:creator>
		<pubDate>Tue, 08 Apr 2008 00:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-100</guid>
		<description>Well, theres much more easier way to do it :) no parsing included.

&lt;code&gt;public static function getHtmlCaretPosition( target:UIComponent, caret:int ):int
{
&#160;&#160;&#160;&#160;var range:TextRange = new TextRange( target, false, 0, caret );
&#160;&#160;&#160;&#160;var pattern:RegExp = /(.*?)(&lt;\/([^&lt;&gt;]*&gt;&lt;\/[^&lt;&gt;]*)*&gt;)/gm;
&#160;&#160;&#160;&#160;var cleanHtml:String = range.htmlText.replace( pattern, &quot;$1&quot;);
&#160;&#160;&#160;&#160;var htmlLength:int = cleanHtml.length-1;
&#160;&#160;&#160;&#160;return htmlLength;
}&lt;/code&gt;
Ive almost used your code, but it seemed a bit too complicated for such an easy task ;)
cheers</description>
		<content:encoded><![CDATA[<p>Well, theres much more easier way to do it <img src='http://www.flexer.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  no parsing included.</p>
<p><code>public static function getHtmlCaretPosition( target:UIComponent, caret:int ):int<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;var range:TextRange = new TextRange( target, false, 0, caret );<br />
&nbsp;&nbsp;&nbsp;&nbsp;var pattern:RegExp = /(.*?)(< \/([^<>]*>< \/[^<>]*)*>)/gm;<br />
&nbsp;&nbsp;&nbsp;&nbsp;var cleanHtml:String = range.htmlText.replace( pattern, "$1");<br />
&nbsp;&nbsp;&nbsp;&nbsp;var htmlLength:int = cleanHtml.length-1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return htmlLength;<br />
}</code><br />
Ive almost used your code, but it seemed a bit too complicated for such an easy task <img src='http://www.flexer.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-92</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Wed, 26 Mar 2008 15:16:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-92</guid>
		<description>New article &lt;a href=&quot;http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; with the new &lt;strong&gt;calculateHtmlPosition&lt;/strong&gt; function modified to repair the flaws mentioned by Rick in previous comments.</description>
		<content:encoded><![CDATA[<p>New article <a href="http://www.flexer.info/2008/03/26/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield-update/" rel="nofollow">here</a> with the new <strong>calculateHtmlPosition</strong> function modified to repair the flaws mentioned by Rick in previous comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FLEX{er} &#187; Blog Archive &#187; Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField) - UPDATE</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-91</link>
		<dc:creator>FLEX{er} &#187; Blog Archive &#187; Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField) - UPDATE</dc:creator>
		<pubDate>Wed, 26 Mar 2008 15:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-91</guid>
		<description>[...] Object (RichTextEditor, TextArea, TextField) - UPDATE26.03.08 &#124; Comment?         Table of contentsFind Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField)Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField) - [...]</description>
		<content:encoded><![CDATA[<div style="padding: 1em; background: #d3e1ef; /* border: dotted 1px #777777; */">
<p>[...] Object (RichTextEditor, TextArea, TextField) &#8211; UPDATE26.03.08 | Comment?         Table of contentsFind Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField)Find Cursor Position in a HtmlText Object (RichTextEditor, TextArea, TextField) &#8211; [...]</p>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-90</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Wed, 26 Mar 2008 09:07:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-90</guid>
		<description>Yes, the code is a bit messed up but we will fix it.</description>
		<content:encoded><![CDATA[<p>Yes, the code is a bit messed up but we will fix it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Banghart</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-88</link>
		<dc:creator>Rick Banghart</dc:creator>
		<pubDate>Tue, 25 Mar 2008 18:01:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-88</guid>
		<description>Sorry, but the code I just posted has the &lt; and &gt; failing to display. If it&#039;s impossible to understand let me know and I can send it to you.</description>
		<content:encoded><![CDATA[<p>Sorry, but the code I just posted has the &lt; and &gt; failing to display. If it&#8217;s impossible to understand let me know and I can send it to you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Banghart</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-87</link>
		<dc:creator>Rick Banghart</dc:creator>
		<pubDate>Tue, 25 Mar 2008 17:55:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-87</guid>
		<description>What follows is the function I came up with, thanks to the inspiration from your original function. This hasn&#039;t yet been thoroughly tested, but it seems to be working in my application. You&#039;ll notice that I chose to grab the entire tag once currentChar = &lt;. I think it simplifies things some, and makes it much easier to respond to certain tags. Note that this assumes that htmlstr is proper html. I don&#039;t have the error checking in place in case there is no &gt; following the &lt;.
&lt;code&gt;
function calculateHtmlPosition(htmlstr:String, pos:int):int {
&#160;&#160;&#160;&#160;if (pos &lt;= -1) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return -1;
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;var htmlPos:int = 0;
&#160;&#160;&#160;&#160;var isInsideEscape:Boolean = false;
&#160;&#160;&#160;&#160;var cnt:int = 0;
&#160;&#160;&#160;&#160;for (var i:int = 0; i &lt; htmlstr.length; i++) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (cnt &gt;= pos) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;break;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var foundTag:Boolean = false;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var currentChar:String = htmlstr.charAt(i);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (currentChar == &quot;&lt;&quot;) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// found the open bracket, now retrieve the rest of the tag
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;foundTag = true;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var endOfTag:int = htmlstr.indexOf(&quot;&gt;&quot;,i);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var tag:String = htmlstr.substring(i,endOfTag + 1);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;i = endOfTag;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (tag == &quot;&lt;/P&gt;&quot;) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cnt++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (currentChar == &quot;&amp;&quot;) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;isInsideEscape = true;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (isInsideEscape) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if(currentChar == &quot;;&quot;) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;isInsideEscape = false;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (!isInsideEscape &amp;&amp; !foundTag) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cnt++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;return i;
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>What follows is the function I came up with, thanks to the inspiration from your original function. This hasn&#8217;t yet been thoroughly tested, but it seems to be working in my application. You&#8217;ll notice that I chose to grab the entire tag once currentChar = &lt;. I think it simplifies things some, and makes it much easier to respond to certain tags. Note that this assumes that htmlstr is proper html. I don&#8217;t have the error checking in place in case there is no &gt; following the &lt;.<br />
<code><br />
function calculateHtmlPosition(htmlstr:String, pos:int):int {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (pos < = -1) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;var htmlPos:int = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;var isInsideEscape:Boolean = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;var cnt:int = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for (var i:int = 0; i < htmlstr.length; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (cnt >= pos) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var foundTag:Boolean = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var currentChar:String = htmlstr.charAt(i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (currentChar == "< ") {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// found the open bracket, now retrieve the rest of the tag<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foundTag = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var endOfTag:int = htmlstr.indexOf(">",i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var tag:String = htmlstr.substring(i,endOfTag + 1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i = endOfTag;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (tag == "") {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (currentChar == "&#038;") {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isInsideEscape = true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isInsideEscape) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(currentChar == ";") {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isInsideEscape = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!isInsideEscape &#038;&#038; !foundTag) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;return i;<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/comment-page-1/#comment-80</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Mon, 24 Mar 2008 07:54:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/18/find-cursor-position-in-a-htmltext-object-richtexteditor-textarea-textfield/#comment-80</guid>
		<description>Yes Rick! You&#039;re right. Can you post your modified function into a comment and I&#039;ll add them right into the article?</description>
		<content:encoded><![CDATA[<p>Yes Rick! You&#8217;re right. Can you post your modified function into a comment and I&#8217;ll add them right into the article?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

