}
return false;
}
public boolean keyTyped (char character) {
final BitmapFont font = style.font;
if (parent.keyboardFocusedActor == this) {
if (character == 8 && (cursor > 0 || hasSelection)) {
if (!hasSelection) {
text = text.substring(0, cursor - 1) + text.substring(cursor);
cursor--;
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
} else {
int minIndex = Math.min(cursor, selectionStart);
int maxIndex = Math.max(cursor, selectionStart);
text = (minIndex > 0 ? text.substring(0, minIndex) : "")
+ (maxIndex < text.length() ? text.substring(maxIndex, text.length()) : "");
cursor = minIndex;
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
hasSelection = false;
}
}
if (character == 127 && (cursor < text.length() || hasSelection)) {
if (!hasSelection) {
text = text.substring(0, cursor) + text.substring(cursor + 1);
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
} else {
int minIndex = Math.min(cursor, selectionStart);
int maxIndex = Math.max(cursor, selectionStart);
text = (minIndex > 0 ? text.substring(0, minIndex) : "")
+ (maxIndex < text.length() ? text.substring(maxIndex, text.length()) : "");
cursor = minIndex;
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
hasSelection = false;
}
}
if (font.containsCharacter(character)) {
if (!hasSelection) {
text = text.substring(0, cursor) + character + text.substring(cursor, text.length());
cursor++;
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
} else {
int minIndex = Math.min(cursor, selectionStart);
int maxIndex = Math.max(cursor, selectionStart);
text = (minIndex > 0 ? text.substring(0, minIndex) : "")
+ (maxIndex < text.length() ? text.substring(maxIndex, text.length()) : "");
cursor = minIndex;
text = text.substring(0, cursor) + character + text.substring(cursor, text.length());
cursor++;
font.computeGlyphAdvancesAndPositions(text, glyphAdvances, glyphPositions);
hasSelection = false;
}
}
if (listener != null) listener.keyTyped(this, character);
return true;