Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had a bit of a dig &amp; unfortunately can't see a workaround... Although one thing I noticed while debugging the javascript, it seems like the problem is actually with the range object itself rather than with the subsequent <code>range.select()</code>. If you look at the values on the range object that <code>selection.createRange()</code> returns, yes the parent dom object may be correct, but the positioning info is already referring to the start of the next line (i.e. offsetLeft/Top, boundingLeft/Top, etc are already wrong).</p> <p>Based on the info <a href="http://www.quirksmode.org/dom/range_intro.html" rel="nofollow noreferrer">here</a>, <a href="http://www.quirksmode.org/dom/w3c_range.html" rel="nofollow noreferrer">here</a> and <a href="http://msdn.microsoft.com/en-us/library/ms535872(VS.85).aspx" rel="nofollow noreferrer">here</a>, I think you're out of luck with IE, since you only have access to Microsoft's TextRange object, which appears to be broken. From my experimentation, you can move the range around and position it exactly where it should be, but once you do so, the range object automatically shifts down to the next line even before you've tried to <code>.select()</code> it. For example, you can see the problem by putting this code in between your Step 1 &amp; Step 2:</p> <pre><code>if (range.boundingWidth == 0) { //looks like its already at the start of the next line down... alert('default position: ' + range.offsetLeft + ', ' + range.offsetTop); //lets move the start of the range one character back //(i.e. select the last char on the line) range.moveStart("character", -1); //now the range looks good (except that its width will be one char); alert('one char back: ' + range.offsetLeft + ', ' + range.offsetTop); //calculate the true end of the line... var left = range.offsetLeft + range.boundingWidth; var top = range.offsetTop; //now we can collapse back down to 0 width range range.collapse(); //the position looks right alert('moving to: ' + left + ', ' + top); //move there. range.moveToPoint(left, top); //oops... on the next line again... stupid IE. alert('moved to: ' + range.offsetLeft + ', ' + range.offsetTop); } </code></pre> <p>So, unfortunately it doesn't look like there's any way to ensure that the range is in the right spot when you select it again.</p> <p>Obviously there's the trivial fix to your code above, by changing Step 2 it to this:</p> <pre><code>// Step 2 Restore the selection if (range.select) { if (range.boundingWidth &gt; 0) { range.select(); } } else { selection.removeAllRanges(); selection.addRange(range); doc.body.focus(); } </code></pre> <p>But presumably, you actually want to do something between Step 1 &amp; Step 2 in your actual which involves moving the selection, hence the need to re-set it. But just in case. :)</p> <p>So, the best I can do is go &amp; vote for the bug you created... Hopefully they'll fix it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload