Change-Id: Ibca58259a0bbcda7141b996020bae8614f0c2114tags/7.7.0.alpha3
@@ -423,7 +423,7 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, | |||
*/ | |||
protected boolean updateCursorPosition() { | |||
if (WidgetUtil.isAttachedAndDisplayed(this)) { | |||
int cursorPos = getCursorPos(); | |||
int cursorPos = prompting ? 0 : getCursorPos(); | |||
if (lastCursorPos != cursorPos) { | |||
client.updateVariable(paintableId, | |||
TextFieldConstants.VAR_CURSOR, cursorPos, false); |
@@ -0,0 +1,42 @@ | |||
package com.vaadin.tests.components.textfield; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
public class InputPromptAndCursorPosition extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final TextField tf = new TextField(); | |||
tf.setColumns(40); | |||
tf.setValue("Delete this text to reveal input prompt and update cursor position."); | |||
tf.setInputPrompt("This is an input prompt"); | |||
final Label l = new Label("Cursor position: ?"); | |||
Button button = new Button("Update cursor position", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
l.setValue("Cursor position: " + tf.getCursorPosition()); | |||
} | |||
}); | |||
addComponent(tf); | |||
addComponent(l); | |||
addComponent(button); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Cursor position should always be zero when input prompt is displayed."; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 19766; | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.vaadin.tests.components.textfield; | |||
import static org.junit.Assert.assertEquals; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.LabelElement; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class InputPromptAndCursorPositionTest extends MultiBrowserTest { | |||
@Test | |||
public void verifyDatePattern() { | |||
openTestURL(); | |||
// Clear the current value and reveal the input prompt. | |||
TextFieldElement textFieldElement = $(TextFieldElement.class).get(0); | |||
textFieldElement.setValue(""); | |||
// Update cursor position. | |||
$(ButtonElement.class).get(0).click(); | |||
// The cursor position should now be zero (not the input prompt length). | |||
LabelElement cursorPosLabel = $(LabelElement.class).get(1); | |||
assertEquals(cursorPosLabel.getText(), "Cursor position: 0"); | |||
} | |||
} |