From 2cbf0958260ce2329bd421ce0ef18843461652e6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Dec 2022 11:48:45 +0100 Subject: [PATCH] Add autoscroll --- .../advancedscripts/screen/ScriptEditScreen.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java index 6f0ea59..b4daf11 100644 --- a/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java +++ b/src/main/java/de/zonlykroks/advancedscripts/screen/ScriptEditScreen.java @@ -332,6 +332,7 @@ public class ScriptEditScreen extends Screen { savedCursorY = -1; savedCursorX = -1; } + autoScroll(); } @Override @@ -360,6 +361,7 @@ public class ScriptEditScreen extends Screen { boolean valid = insert(chr + ""); savedCursorY = -1; savedCursorX = -1; + autoScroll(); return valid; } @@ -540,6 +542,14 @@ public class ScriptEditScreen extends Screen { return true; } + private void autoScroll() { + if (cursorY < scroll) { + scroll = cursorY; + } else if (cursorY >= scroll + ((this.height - 25 - 66) / 9)) { + scroll = cursorY - ((this.height - 25 - 66) / 9); + } + } + private boolean isAtEndOfLine() { return cursorX == lines.get(cursorY).length(); }