diff --git a/h2d/Text.hx b/h2d/Text.hx index 34e1c4231..f356929a8 100644 --- a/h2d/Text.hx +++ b/h2d/Text.hx @@ -352,6 +352,8 @@ class Text extends Drawable { } else { maxWidth -= afterData; } + if (maxWidth <= 2) + return text; if ( font == null ) font = this.font; var lines = []; var x = leftMargin; diff --git a/h2d/TextInput.hx b/h2d/TextInput.hx index 316a1d35b..1b8127b95 100644 --- a/h2d/TextInput.hx +++ b/h2d/TextInput.hx @@ -289,11 +289,11 @@ class TextInput extends Text { return; case K.C if (K.isDown(K.CTRL)): if( text != "" && selectionRange != null ) { - hxd.System.setClipboardText(text.substr(selectionRange.start, selectionRange.length)); + hxd.System.setClipboardText(getSelectedText()); } case K.X if (K.isDown(K.CTRL)): if( text != "" && selectionRange != null ) { - if(hxd.System.setClipboardText(text.substr(selectionRange.start, selectionRange.length))) { + if(hxd.System.setClipboardText(getSelectedText())) { if( !canEdit ) return; beforeChange(); cutSelection(); @@ -435,9 +435,13 @@ class TextInput extends Text { if (cursorIndex >= len) { return len; } + // ret walks the text itself, so it stops at the end of the TEXT: getTextLength + // is the expanded length, longer than the text by one per inserted line break, + // and bounding a text position with it runs past the end. + var max = text.length; var ret = getTextPos(cursorIndex); - while (ret < len && isWordLimit(ret)) ret++; - while (ret < len && !isWordLimit(ret)) ret++; + while (ret < max && isWordLimit(ret)) ret++; + while (ret < max && !isWordLimit(ret)) ret++; return getCursorPos(ret); }