summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorGuillermo Alvarez <guillermo@vaadin.com>2014-08-11 10:56:58 +0300
committerBogdan Udrescu <bogdan@vaadin.com>2014-08-13 10:39:04 +0300
commit5edc32fa0ba7a7c29190f57697b4398a78d05dd2 (patch)
treee2343a230210a4f34790a19c74b3de58feb0a474 /client
parent37b8142db5ceabe60cb0449fbc1164d153db7488 (diff)
downloadvaadin-framework-5edc32fa0ba7a7c29190f57697b4398a78d05dd2.tar.gz
vaadin-framework-5edc32fa0ba7a7c29190f57697b4398a78d05dd2.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
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/Util.java34
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java31
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 49c862006b..e37b044826 100644
--- a/client/src/com/vaadin/client/Util.java
+++ b/client/src/com/vaadin/client/Util.java
@@ -1420,6 +1420,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, ...
@@ -1571,7 +1602,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 6ba0785acc..516fe5e9b3 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -1057,11 +1057,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
@@ -1456,9 +1478,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);