diff options
author | Guillermo Alvarez <guillermo@vaadin.com> | 2014-08-11 10:56:58 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2014-08-28 19:18:07 +0300 |
commit | a964b861f8130b11f4bea9d8d6faa63ccab9476c (patch) | |
tree | 72520f964342fc9723b2c31254d74ee4cd6a489d | |
parent | 0d8478158221e27acdee22a8ae8d3a74060874a9 (diff) | |
download | vaadin-framework-a964b861f8130b11f4bea9d8d6faa63ccab9476c.tar.gz vaadin-framework-a964b861f8130b11f4bea9d8d6faa63ccab9476c.zip |
Correctly display an item which is too long for the textfield. (#13477)
New JSNI function allows direction parameter in setSelectionRange.
This allows setting selection backward and fixes the issue in FF.
Change-Id: I1e34b70983e3f525b7009668877038f108d286a7
-rw-r--r-- | client/src/com/vaadin/client/Util.java | 34 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VFilterSelect.java | 31 |
2 files changed, 59 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index d5124169b3..fe8ec51401 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -1405,6 +1405,37 @@ public class Util { } /** + * Sets the selection range of an input element. + * + * We need this JSNI function to set selection range so that we can use the + * optional direction attribute to set the anchor to the end and the focus + * to the start. This makes Firefox work the same way as other browsers + * (#13477) + * + * @param elem + * the html input element. + * @param pos + * the index of the first selected character. + * @param length + * the selection length. + * @param direction + * a string indicating the direction in which the selection was + * performed. This may be "forward" or "backward", or "none" if + * the direction is unknown or irrelevant. + * + * @since + */ + public native static void setSelectionRange(Element elem, int pos, + int length, String direction) + /*-{ + try { + elem.setSelectionRange(pos, pos + length, direction); + } catch (e) { + // Firefox throws exception if TextBox is not visible, even if attached + } + }-*/; + + /** * Wrap a css size value and its unit and translate back and forth to the * string representation.<br/> * Eg. 50%, 123px, ... @@ -1556,7 +1587,8 @@ public class Util { * @return true if the two sizes are equals, otherwise false. */ public static boolean equals(String cssSize1, String cssSize2) { - return CssSize.fromString(cssSize1).equals(CssSize.fromString(cssSize2)); + return CssSize.fromString(cssSize1).equals( + CssSize.fromString(cssSize2)); } } diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 26c1970fe8..bc677a838f 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -1049,11 +1049,33 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, @Override public void setSelectionRange(int pos, int length) { if (textInputEnabled) { - super.setSelectionRange(pos, length); + /* + * set selection range with a backwards direction: anchor at the + * back, focus at the front. This means that items that are too + * long to display will display from the start and not the end + * even on Firefox. + * + * We need the JSNI function to set selection range so that we + * can use the optional direction attribute to set the anchor to + * the end and the focus to the start. This makes Firefox work + * the same way as other browsers (#13477) + */ + Util.setSelectionRange(getElement(), pos, length, "backward"); + } else { - super.setSelectionRange(0, getValue().length()); + /* + * Setting the selectionrange for an uneditable textbox leads to + * unwanted behaviour when the width of the textbox is narrower + * than the width of the entry: the end of the entry is shown + * instead of the beginning. (see #13477) + * + * To avoid this, we set the caret to the beginning of the line. + */ + + super.setSelectionRange(0, 0); } } + } @Deprecated @@ -1448,9 +1470,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, private void setText(final String text) { /** - * To leave caret in the beginning of the line. - * SetSelectionRange wouldn't work on IE - * (see #13477) + * To leave caret in the beginning of the line. SetSelectionRange + * wouldn't work on IE (see #13477) */ Direction previousDirection = tb.getDirection(); tb.setDirection(Direction.RTL); |