diff options
author | Lulonaut <67191924+Lulonaut@users.noreply.github.com> | 2022-05-22 11:06:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-22 11:06:01 +0200 |
commit | 6a997f1670df7f7112e7616c0f02fcc490289946 (patch) | |
tree | 717272ea715390134639cbcb70a8784daea74f1f /src/main/java/io | |
parent | 7de14ba5f7914ee9528c7a8efd834f66e2a92db5 (diff) | |
download | NotEnoughUpdates-6a997f1670df7f7112e7616c0f02fcc490289946.tar.gz NotEnoughUpdates-6a997f1670df7f7112e7616c0f02fcc490289946.tar.bz2 NotEnoughUpdates-6a997f1670df7f7112e7616c0f02fcc490289946.zip |
allow pasting formatted text (#144)
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java | 14 |
1 files changed, 14 insertions, 0 deletions
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)"); |