<div dir="ltr">Hi Dan,<div><br></div><div>Thanks for your quick feedback.</div><div>Please see my comments inline.</div><div><br></div><div><br><div class="gmail_quote">On Wed, Jun 2, 2010 at 9:30 AM, Dan Bernstein <span dir="ltr">&lt;<a href="mailto:mitz@apple.com" target="_blank">mitz@apple.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div><div>On Jun 1, 2010, at 10:48 PM, Xiaomei Ji wrote:</div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><br><div dir="ltr"><font face="arial, helvetica, sans-serif">Given a DOM Node and an InlineBox, is there a way to convert the character offset within this InlineBox to a VisiblePosition? considering bidi/RTL.</font></div>


</div></div></blockquote><div><br></div></div><div>Not sure how being given a DOM node helps here…</div></div></div></blockquote><div><br></div><div>The node is just for constructing the position.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word"><div><div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div>

<font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Using &lt;span&gt; node in the following example as an example:</font></div>

<div><span style="border-collapse:collapse;white-space:pre"><font face="arial, helvetica, sans-serif">&lt;div contenteditable dir=rtl&gt;abc ששש def &lt;span dir=ltr&gt;שנב abc סטז&lt;/span&gt; uvw זזז xyz&lt;/div&gt; </font></span></div>





<span style="border-collapse:collapse"><pre style="white-space:pre-wrap;width:50em"><span style="white-space:pre"><font face="arial, helvetica, sans-serif">Assume the &lt;span&gt; node is node A, using &quot;(node, offset)a&quot; to represent the node and offset information of Position when caret is before character &quot;a&quot;, the position information are:</font></span></pre>





<pre style="white-space:pre-wrap;width:50em"><span style="white-space:pre"><font face="arial, helvetica, sans-serif">...... (A, 4)a(A, 5)b(A, 6)c(A, 7) (A, 0xb)ז(A, 0xa)ט(A, 9)ס(A, 8).
  </font></span></pre></span><div><font><span style="border-collapse:collapse;white-space:pre"><font face="arial, helvetica, sans-serif">Given the &lt;span&gt; node, the InlineBox representing &quot; abc &quot;(with surrounding spaces), and character offset 5 within the InlineBox, is there a way to convert offset 5 into VisiblePosition (A, 0xb) (not (A, 8))? which means when caret is placed after the 2nd space in &quot; abc &quot;, the visible position is (A, 0xb).</font></span></font></div>


</div></div></div></blockquote><div><br></div></div><div>I don’t think there’s code to do this—hit testing code will just choose the DOM offset that corresponds to the line box you hit—but how about something like this?</div>


<div><br></div><div><ol><li>If the offset is not at the edge of the text box, then just map it to that box’s text node</li><li>Otherwise, if there is an adjacent text box on that edge, and it has the same direction as the first text box, just map to the first text box’s text node (or, perhaps you should look at the bidi levels of both boxes and choose the one with the higher level?)</li>


<li>Otherwise, of the two adjacent text boxes, choose the one whose direction is equal to the block direction, and return an offset into the chosen box’s text node, corresponding to the edge</li></ol><div><br></div><div>

Does this cover all cases?</div></div></div></div></blockquote><div><br></div><div>Looks like it works. I tried pure LTR text, RTL text, and mixed text in RTL div, LTR div, div with span having the same direction, and div with span having different direction.</div>

<div>Except one case it does not work correctly (neither arrow key works correctly).</div><div><div>&lt;div contenteditable id=&quot;multiple_space_wrong_result&quot;&gt;abc ששש def &lt;span dir=rtl&gt;שנב  opq סטז&lt;/span&gt;  uvw ששש xyz&lt;/div&gt;</div>

</div><div>Note: there are 2 spaces between &quot;שנב&quot; and &quot;opq&quot; in &lt;span&gt; node.</div><div><br></div><div>The position information of the span node are:</div><div>(node, 12)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">ז</span>(node, 11)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">ט</span>(node, 10)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">ס</span>(node, 9) (?)o(node, 6)p(node, 7)q(node, 8) (node, 3)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">ב</span>(node, 2)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">נ</span>(node, 1)<span style="font-family:&#39;Times New Roman&#39;;font-size:medium">ש</span>(node, 4)</div>

<div>Note: I am not able to place caret before &#39;o&#39;.</div><div><br></div><div>When offset is at the left edge of text box &quot; opq &quot;, the chosen box will be text box &quot; opq &quot; since it has the same directionality as that of its enclosing box. The computed position will be (node, 4) since 4 is the min caret offset of text box &quot; opq &quot;.</div>
<div>It is wrong because (node, 4) is at the right edge of text box &quot;שנב&quot;.  </div><div><br></div><div>When there is no extra space between  &quot;שנב&quot; and &quot;opq&quot; in &lt;span&gt; node, the computation works correctly.</div>
<div><br></div><div><br></div><div>Thanks,</div><div>Xiaomei</div><div><br></div><div><br></div><div><br></div><div><br></div></div><br></div></div>