mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Fixed CTRL+D crash
This commit is contained in:
1 parent
8220bbd327
commit
d2bc98a4c1
1 file changed
+4
-2
@@ -1085,9 +1085,11 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
// Duplicate current line
|
||||
for (LineData line : container.lines) {
|
||||
if (selection.getCursorPosition() >= line.start && selection.getCursorPosition() <= line.end) {
|
||||
String lineText = text.substring(line.start, line.end);
|
||||
int safeStart = Math.max(0, Math.min(line.start, text.length()));
|
||||
int safeEnd = Math.max(safeStart, Math.min(line.end, text.length()));
|
||||
String lineText = text.substring(safeStart, safeEnd);
|
||||
String insertText = lineText.endsWith("\n") ? lineText : "\n" + lineText;
|
||||
int insertionPoint = line.end;
|
||||
int insertionPoint = Math.min(line.end, text.length());
|
||||
setText(text.substring(0, insertionPoint) + insertText + text.substring(insertionPoint));
|
||||
int newCursor = insertionPoint + insertText.length() - (insertText.endsWith("\n") ? 1 : 0);
|
||||
selection.reset(Math.max(0, Math.min(newCursor, this.text.length())));
|
||||
|
||||
Reference in new issue
Block a user