diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java index a25882724..b384186e8 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -355,17 +355,20 @@ public class GuiScriptTextArea extends GuiNpcTextField { private int getSelectionPos(int xMouse, int yMouse) { xMouse -= (this.x + LINE_NUMBER_GUTTER_WIDTH + 1); yMouse -= this.y + 1; - // Adjust yMouse to account for fractional GL translation (negative offset applied in rendering) + // Adjust yMouse to account for fractional GL translation (negative offset applied in rendering). + // Use a double here (no integer rounding) so clicks that land on partially + // visible lines (fractional positions) correctly hit that line. double fracPixels = scroll.getFractionalOffset() * container.lineHeight; - yMouse = (int) Math.round(yMouse + fracPixels); + double yMouseD = yMouse + fracPixels; ArrayList list = new ArrayList(this.container.lines); for (int i = 0; i < list.size(); ++i) { LineData data = (LineData) list.get(i); - if (i >= scroll.getScrolledLine() && i <= scroll.getScrolledLine() + this.container.visibleLines) { - int yPos = (i - scroll.getScrolledLine()) * this.container.lineHeight; - if (yMouse >= yPos && yMouse < yPos + this.container.lineHeight) { + //+1 to account for the fractional line + if (i >= scroll.getScrolledLine() && i <= scroll.getScrolledLine() + this.container.visibleLines +1) { + double yPos = (i - scroll.getScrolledLine()) * this.container.lineHeight; + if (yMouseD >= yPos && yMouseD < yPos + this.container.lineHeight) { int lineWidth = 0; char[] chars = data.text.toCharArray(); diff --git a/src/main/java/noppes/npcs/client/gui/util/script/ScrollState.java b/src/main/java/noppes/npcs/client/gui/util/script/ScrollState.java index b092cd7fe..2649563ff 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/ScrollState.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/ScrollState.java @@ -15,7 +15,7 @@ public class ScrollState { private double scrollVelocity = 0.0; // Last timestamp for delta time calculation private long lastScrollTime = 0L; - // Integer line index for compatibility with rendering + // First visible line private int scrolledLine = 0; // Scrollbar drag offset when dragging thumb private int scrollbarDragOffset = 0; @@ -136,7 +136,11 @@ public class ScrollState { // Getters public double getScrollPos() { return scrollPos; } public double getTargetScroll() { return targetScroll; } - public int getScrolledLine() { return scrolledLine; } + + /** @return First visible line **/ + public int getScrolledLine() { + return scrolledLine; + } public double getScrollVelocity() { return scrollVelocity; } public boolean isClickScrolling() { return clickScrolling; } public int getScrollbarDragOffset() { return scrollbarDragOffset; }