diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WDoubleEdit.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WDoubleEdit.java index dd069183699..5d8ce011d6a 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WDoubleEdit.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WDoubleEdit.java @@ -95,7 +95,7 @@ private boolean filter(String text, char c) { boolean good; boolean validate = true; - if (c == '-' && !text.contains("-") && textBox.cursor == 0) { + if (c == '-' && !text.contains("-") && Math.min(textBox.selectionStart, textBox.selectionEnd) == 0) { good = true; validate = false; } else if (c == '.' && !text.contains(".")) { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WIntEdit.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WIntEdit.java index c6231b16193..41741f5fe75 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WIntEdit.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WIntEdit.java @@ -82,7 +82,7 @@ private boolean filter(String text, char c) { boolean good; boolean validate = true; - if (c == '-' && !text.contains("-") && textBox.cursor == 0) { + if (c == '-' && !text.contains("-") && Math.min(textBox.selectionStart, textBox.selectionEnd) == 0) { good = true; validate = false; } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WLongEdit.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WLongEdit.java index b1f0b283101..50accf82fe9 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WLongEdit.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WLongEdit.java @@ -54,7 +54,7 @@ private boolean filter(String text, char c) { boolean good; boolean validate = true; - if (c == '-' && !text.contains("-") && textBox.cursor == 0) { + if (c == '-' && !text.contains("-") && Math.min(textBox.selectionStart, textBox.selectionEnd) == 0) { good = true; validate = false; } else { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java index 318c45f8643..cc3b4ef245b 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java @@ -559,19 +559,28 @@ private int getSelectedCompletion() { public boolean onCharTyped(CharacterEvent input) { if (!focused) return false; - if (filter.filter(text, input.codepoint())) { - clearSelection(); + int start = Math.min(selectionStart, selectionEnd); + int end = Math.max(selectionStart, selectionEnd); - text = text.substring(0, cursor) + input.codepointAsString() + text.substring(cursor); + String newText = text; + if (start != end) { + newText = text.substring(0, start) + text.substring(end); + } - cursor++; - resetSelection(); + if (!filter.filter(newText, input.codepoint())) return false; - runAction(); - return true; - } + String inserted = input.codepointAsString(); - return false; + text = newText.substring(0, start) + + inserted + + newText.substring(start); + + cursor = start + inserted.length(); + + resetSelection(); + runAction(); + + return true; } @Override