google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

fillText with cursor management #142

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Use Browser.fillText(textBox, false, "bordeaux")
2.each char is placed at the begining of the field
For example: 
"b" is the first char, 
next char is "o" so the field is filled with "ob", 
next char is "r" so the field is filled with "rob", 
next char is "d" so the field is filled with "drob",
next char is "e" so the field is filled with "edrob",
next char is "a" so the field is filled with "aedrob",
next char is "u" so the field is filled with "uaedrob",
next char is "x" so the field is filled with "xuaedrob",

What is the expected output? What do you see instead?
the expected behavior is to add each char at the end of field

What version of the product are you using? On what operating system?
0.33.1 on Windows 7

Please provide any additional information below.

this is an example of the expected behavior (there is only two new lines) :

public static void fillText(TextBox hasTextWidget, boolean check, String value) 
throws IllegalArgumentException {
        if (value == null || "".equals(value)) {
            throw new IllegalArgumentException("Cannot fill a null or empty text. If you intent to remove some text, use '" + Browser.class.getSimpleName()
                    + ".emptyText(..)' instead");
        }
        if (!Widget.class.isInstance(hasTextWidget)) {
            return;
        }

        boolean changed = false;

        for (int i = 0; i < value.length(); i++) {

            int keyCode = value.charAt(i);

            // trigger keyDown and keyPress
            Event keyDownEvent = EventBuilder.create(Event.ONKEYDOWN).setKeyCode(keyCode).build();
            Event keyPressEvent = EventBuilder.create(Event.ONKEYPRESS).setKeyCode(keyCode).build();

            // --- new code ---
            JavaScriptObjects.setProperty(hasTextWidget.getElement(), JsoProperties.SELECTION_START, i);
            JavaScriptObjects.setProperty(hasTextWidget.getElement(), JsoProperties.SELECTION_END, i);

            dispatchEventInternal((Widget) hasTextWidget, check, keyDownEvent, keyPressEvent);

            // check if one on the events has been prevented
            boolean keyDownEventPreventDefault = JavaScriptObjects.getBoolean(keyDownEvent, JsoProperties.EVENT_PREVENTDEFAULT);
            boolean keyPressEventPreventDefault = JavaScriptObjects.getBoolean(keyPressEvent, JsoProperties.EVENT_PREVENTDEFAULT);

            if (!keyDownEventPreventDefault && !keyPressEventPreventDefault) {
                hasTextWidget.setText(value.substring(0, i + 1));
                changed = true;
            }

            // trigger keyUp
            Event keyUpEvent = EventBuilder.create(Event.ONKEYUP).setKeyCode(keyCode).build();
            dispatchEventInternal((Widget) hasTextWidget, check, keyUpEvent);

            if (changed && HasValueChangeHandlers.class.isInstance(hasTextWidget)) {
                ValueChangeEvent.fire((HasValueChangeHandlers) hasTextWidget, value.substring(0, i + 1));
            }
        }

        // no need to check event anymore
        dispatchEventInternal((Widget) hasTextWidget, false, EventBuilder.create(Event.ONBLUR).build());

        if (changed) {
            dispatchEventInternal((Widget) hasTextWidget, false, EventBuilder.create(Event.ONCHANGE).build());
        }
    }

Original issue reported on code.google.com by sebastie...@gmail.com on 3 May 2012 at 3:11

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 5 May 2012 at 9:47

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 7 May 2012 at 3:13

GoogleCodeExporter commented 9 years ago
I've added the new lines of code and just deployed a new 0.33.4-SNAPSHOT. Could 
you please give it a try and post some feedback here ?

Thanks !

Original comment by gael.laz...@gmail.com on 7 May 2012 at 9:34