Fix NPE when inserting new line anywhere but at the end

This commit is contained in:
johni0702
2015-08-16 11:33:52 +02:00
parent 7808f37c5e
commit 8d7bc1b8d6
2 changed files with 113 additions and 104 deletions

View File

@@ -252,7 +252,7 @@ public abstract class AbstractGuiTextArea<T extends AbstractGuiTextArea<T>>
newText[cursorY + 1] = text[cursorY].substring(cursorX); newText[cursorY + 1] = text[cursorY].substring(cursorX);
if (cursorY + 1 < text.length) { if (cursorY + 1 < text.length) {
System.arraycopy(text, cursorY + 1, newText, cursorY + 1, text.length - cursorY - 1); System.arraycopy(text, cursorY + 1, newText, cursorY + 2, text.length - cursorY - 1);
} }
text = newText; text = newText;
selectionX = cursorX = 0; selectionX = cursorX = 0;

View File

@@ -250,7 +250,7 @@ public class GuiTextArea extends Gui implements GuiElement, GuiOutsideClickableE
newText[cursorY + 1] = text[cursorY].substring(cursorX); newText[cursorY + 1] = text[cursorY].substring(cursorX);
if (cursorY + 1 < text.length) { if (cursorY + 1 < text.length) {
System.arraycopy(text, cursorY + 1, newText, cursorY + 1, text.length - cursorY - 1); System.arraycopy(text, cursorY + 1, newText, cursorY + 2, text.length - cursorY - 1);
} }
text = newText; text = newText;
selectionX = cursorX = 0; selectionX = cursorX = 0;
@@ -510,6 +510,7 @@ public class GuiTextArea extends Gui implements GuiElement, GuiOutsideClickableE
return; return;
} }
try {
if (GuiScreen.isCtrlKeyDown()) { if (GuiScreen.isCtrlKeyDown()) {
switch (keyCode) { switch (keyCode) {
case Keyboard.KEY_A: // Select all case Keyboard.KEY_A: // Select all
@@ -623,6 +624,14 @@ public class GuiTextArea extends Gui implements GuiElement, GuiOutsideClickableE
selectionX = cursorX; selectionX = cursorX;
selectionY = cursorY; selectionY = cursorY;
} }
} finally {
System.out.println(cursorX + "/" + cursorY);
System.out.println(selectionX + "/" + selectionY);
System.out.println("Lines (" + text.length + "): ");
for (String line : text) {
System.out.println(line);
}
}
} }
@Override @Override