|
@@ -104,8 +104,8 @@ class TextInput extends Text {
|
|
|
case K.BACKSPACE:
|
|
|
if( cursorIndex > 0 && canEdit ) {
|
|
|
beforeChange();
|
|
|
- text = text.substr(0, cursorIndex - 1) + text.substr(cursorIndex);
|
|
|
cursorIndex--;
|
|
|
+ text = text.substr(0, cursorIndex) + text.substr(cursorIndex + 1);
|
|
|
onChange();
|
|
|
}
|
|
|
case K.ENTER, K.NUMPAD_ENTER:
|
|
@@ -228,6 +228,12 @@ class TextInput extends Text {
|
|
|
return selectionRange == null ? null : text.substr(selectionRange.start, selectionRange.length);
|
|
|
}
|
|
|
|
|
|
+ override function set_text(t:hxd.UString) {
|
|
|
+ super.set_text(t);
|
|
|
+ if( cursorIndex > t.length ) cursorIndex = t.length;
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+
|
|
|
override function set_font(f) {
|
|
|
super.set_font(f);
|
|
|
cursorTile = h2d.Tile.fromColor(0xFFFFFF, 1, font.size);
|
|
@@ -236,6 +242,11 @@ class TextInput extends Text {
|
|
|
return f;
|
|
|
}
|
|
|
|
|
|
+ override function initGlyphs(text:hxd.UString, rebuild = true, handleAlign = true, lines:Array<Int> = null):Void {
|
|
|
+ super.initGlyphs(text, rebuild, handleAlign, lines);
|
|
|
+ if( rebuild ) this.calcWidth += cursorTile.width; // cursor end pos
|
|
|
+ }
|
|
|
+
|
|
|
function textPos( x : Float, y : Float ) {
|
|
|
x += scrollX;
|
|
|
var pos = 0;
|
|
@@ -277,6 +288,7 @@ class TextInput extends Text {
|
|
|
if( selectionSize == 0 ) {
|
|
|
selectionPos = calcTextWidth(text.substr(0, selectionRange.start));
|
|
|
selectionSize = calcTextWidth(text.substr(selectionRange.start, selectionRange.length));
|
|
|
+ if( selectionRange.start + selectionRange.length == text.length ) selectionSize += cursorTile.width; // last pixel
|
|
|
}
|
|
|
selectionTile.dx += selectionPos;
|
|
|
selectionTile.width += selectionSize;
|