From 6a997f1670df7f7112e7616c0f02fcc490289946 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Sun, 22 May 2022 11:06:01 +0200 Subject: allow pasting formatted text (#144) --- .../notenoughupdates/itemeditor/GuiElementTextField.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java index fd78f3aa..95dbeccd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java @@ -210,6 +210,20 @@ public class GuiElementTextField extends GuiElement { @Override public void keyTyped(char typedChar, int keyCode) { if (focus) { + //allows for pasting formatted text that includes "§" + if (GuiScreen.isKeyComboCtrlV(keyCode)) { + //The cursor position gets set to the end when using setText + int oldCursorPosition = textField.getCursorPosition(); + + String clipboardContent = GuiScreen.getClipboardString(); + StringBuilder stringBuilder = new StringBuilder(getText()) + .insert(textField.getCursorPosition(), clipboardContent); + + //writeText removes unwanted chars from the String which includes "§" + textField.setText(stringBuilder.toString()); + textField.setCursorPosition(oldCursorPosition + clipboardContent.length()); + } + if ((options & MULTILINE) != 0) { //Carriage return Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n])(?!\\u00B6)"); -- cgit