package com.xtremelabs.robolectric.shadows;

import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.widget.EditText;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;

/**
 * A shadow for EditText that provides support for listeners
 */
@SuppressWarnings({"UnusedDeclaration"})
@Implements(EditText.class)
public class ShadowEditText extends ShadowTextView {

    private int maxLength = Integer.MAX_VALUE;

    public ShadowEditText() {
        focusable = true;
        focusableInTouchMode = true;
    }

    @Override
    public void applyAttributes() {
        super.applyAttributes();
        maxLength = attributeSet.getAttributeIntValue("android", "maxLength", Integer.MAX_VALUE);
    }

    @Override
    @Implementation(i18nSafe = true)
    public void setText(CharSequence str) {
        if ( !TextUtils.isEmpty(str) && str.length() > maxLength) {
            str = str.subSequence(0, maxLength);
        }
        super.setText(str);
    }

    @Override
    @Implementation
    public Editable getText() {
        CharSequence text = super.getText();
        if (!(text instanceof Editable)) {
            return new SpannableStringBuilder(text);
        }
        return (Editable) text;
    }

}
@@ -528,16 +528,86 @@
 X_VALUE;
+%0A    private int selectionStart = 0;%0A    private int selectionEnd = 0;
 %0A%0A    pu
@@ -1401,9 +1401,445 @@
 %0A    %7D%0A%0A
+    @Implementation%0A    public void setSelection(int index) %7B%0A        setSelection(index, index);%0A    %7D%0A%0A    @Implementation%0A    public void setSelection(int start, int end) %7B%0A        selectionStart = start;%0A        selectionEnd = end;%0A    %7D%0A    %0A    @Implementation%0A    public int getSelectionStart() %7B%0A        return selectionStart;%0A    %7D%0A    %0A    @Implementation%0A    public int getSelectionEnd() %7B%0A        return selectionEnd;%0A    %7D%0A
 %7D

Add support for selection in ShadowEditText