From d028ba6cd2529d18003bcc09a0d7f6be031cbef5 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sun, 19 Jan 2020 11:49:51 +0200 Subject: Add select-all to text fields, fix selections spilling outside the widget Closes #28 and fixes #29. --- .../java/io/github/cottonmc/cotton/gui/widget/WTextField.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 12c6ae6..97023aa 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -390,7 +390,7 @@ public class WTextField extends WWidget { b = a; a = tmp; } - invertedRect(textX+a-1, textY-1, b-a, 12); + invertedRect(textX+a-1, textY-1, Math.min(b-a, width - OFFSET_X_TEXT), 12); // int int_10 = int_6 + MinecraftClient.getInstance().textRenderer.getStringWidth(trimText.substring(0, adjustedCursor)); // var10002 = int_7 - 1; // var10003 = int_10 - 1; @@ -557,7 +557,7 @@ public class WTextField extends WWidget { @Override public void onKeyPressed(int ch, int key, int modifiers) { if (!this.editable) return; - + if (Screen.isCopy(ch)) { String selection = getSelection(); if (selection!=null) { @@ -594,6 +594,10 @@ public class WTextField extends WWidget { } } return; + } else if (Screen.isSelectAll(ch)) { + select = 0; + cursor = text.length(); + return; } //System.out.println("Ch: "+ch+", Key: "+key+", Mod: "+modifiers); -- cgit