From a1322cb474fef6ce3540cea953dbebe4c0968172 Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Wed, 5 Aug 2026 09:01:15 -0700 Subject: [PATCH] fixes word wrap when text length is <2 Fixes highlighting --- h2d/Text.hx | 2 ++ h2d/TextInput.hx | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/h2d/Text.hx b/h2d/Text.hx index a043958b9..1e853881f 100644 --- a/h2d/Text.hx +++ b/h2d/Text.hx @@ -340,6 +340,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 9dd410c15..0ec6e9240 100644 --- a/h2d/TextInput.hx +++ b/h2d/TextInput.hx @@ -286,11 +286,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(); @@ -432,9 +432,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); }