Hi John,

Thank you for quick response.

It is interesting to know the right fix.

Yoshiki

[email protected] さんは書きました:
> Reviewers: jgw,
> 
> Description:
> Description:
> ============
> TextBoxImplIE6#getSelectionLength() uses some hacks to figure out how
> many /r/n appear in a TextArea.  The loop works for a TextArea but can
> result in an infinite loop in a TextBox.
> 
> 
> Fix:
> ====
> This patch splits the implementations for a TextArea and a TextBox,
> since a TextBox in IE cannot have /r/n anyway.  We now use the original
> implementation for TextBoxes.
> 
> 
> Testing:
> =======
> I manually verified that this fixes the associated issue in IE.
> 
> Please review this at http://gwt-code-reviews.appspot.com/52801
> 
> Affected files:
>    user/src/com/google/gwt/user/client/ui/TextArea.java
>    user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
>    user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java
> 
> 
> Index: user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java
> ===================================================================
> --- user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java      
> (revision  
> 5721)
> +++ user/src/com/google/gwt/user/client/ui/impl/TextBoxImpl.java      
> (working  
> copy)
> @@ -44,6 +44,10 @@
>       return getCursorPos(elem);
>     }
> 
> +  public int getTextAreaSelectionLength(Element elem) {
> +    return getSelectionLength(elem);
> +  }
> +
>     public native void setSelectionRange(Element elem, int pos, int length)  
> /*-{
>       try {
>         elem.setSelectionRange(pos, pos + length);
> Index: user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java
> ===================================================================
> --- user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java    
> (revision 5721)
> +++ user/src/com/google/gwt/user/client/ui/impl/TextBoxImplIE6.java    
> (working copy)
> @@ -42,19 +42,7 @@
>         var tr = elem.document.selection.createRange();
>         if (tr.parentElement() !== elem)
>           return 0;
> -      var trLength = tr.text.length;
> -
> -      // Subtract characters from the end to account for trimmed newlines.
> -      var offset = 0;
> -      var tr2 = tr.duplicate();
> -      tr2.moveEnd('character', -1);
> -      var tr2Length = tr2.text.length;
> -      while (tr2Length == trLength && tr2.parentElement() == elem &&  
> tr.compareEndPoints('StartToEnd', tr2) <= 0) {
> -        offset += 2;
> -        tr2.moveEnd('character', -1);
> -        tr2Length = tr2.text.length;
> -      }
> -      return trLength + offset;
> +      return tr.text.length;
>       }
>       catch (e) {
>         return 0;
> @@ -95,6 +83,31 @@
>       }
>     }-*/;
> 
> +  @Override
> +  public native int getTextAreaSelectionLength(Element elem) /*-{
> +    try {
> +      var tr = elem.document.selection.createRange();
> +      if (tr.parentElement() !== elem)
> +        return 0;
> +      var trLength = tr.text.length;
> +
> +      // Subtract characters from the end to account for trimmed newlines.
> +      var offset = 0;
> +      var tr2 = tr.duplicate();
> +      tr2.moveEnd('character', -1);
> +      var tr2Length = tr2.text.length;
> +      while (tr2Length == trLength && tr2.parentElement() == elem &&  
> tr.compareEndPoints('StartToEnd', tr2) <= 0) {
> +        offset += 2;
> +        tr2.moveEnd('character', -1);
> +        tr2Length = tr2.text.length;
> +      }
> +      return trLength + offset;
> +    }
> +    catch (e) {
> +      return 0;
> +    }
> +  }-*/;
> +
>     /**
>      * Moving the start 1 character will move across a \r\n, but \r\n counts  
> as
>      * two characters, so we need to offset the position accordingly.
> Index: user/src/com/google/gwt/user/client/ui/TextArea.java
> ===================================================================
> --- user/src/com/google/gwt/user/client/ui/TextArea.java      (revision 5721)
> +++ user/src/com/google/gwt/user/client/ui/TextArea.java      (working copy)
> @@ -103,7 +103,7 @@
> 
>     @Override
>     public int getSelectionLength() {
> -    return getImpl().getSelectionLength(getElement());
> +    return getImpl().getTextAreaSelectionLength(getElement());
>     }
> 
>     /**
> 
> 
> 
> > 
> 



--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to