From 3bbee227ee855094c89e79125b71de0cf486b2e7 Mon Sep 17 00:00:00 2001 From: Nathan Glenn Date: Fri, 27 Sep 2024 14:54:40 -0500 Subject: [PATCH] Account for half-scrolled lines in right-click When a line is half-scrolled into view in the debugger, we need to take that into account when calculating the line number that was targeted by a right- click. This fixes the issue where the right-click targets always seemed slightly off. Fixes #417. --- .../soar/debugger/helpers/FoldingText.java | 17 ++++++++++------- .../soar/debugger/modules/FoldingTextView.java | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Java/Debugger/src/edu/umich/soar/debugger/helpers/FoldingText.java b/Java/Debugger/src/edu/umich/soar/debugger/helpers/FoldingText.java index 45a50272d2..7b6eb6b0cf 100644 --- a/Java/Debugger/src/edu/umich/soar/debugger/helpers/FoldingText.java +++ b/Java/Debugger/src/edu/umich/soar/debugger/helpers/FoldingText.java @@ -979,16 +979,20 @@ public void expandPage(boolean state) setRedraw(true); } - // Returns the line we clicked on based on mouse coordinates + // Returns the line we clicked on based on text pane mouse Y position public int getLine(int mouseY) { - int topLine = m_Text.getTopIndex(); + int verticalScrollOffset = m_Text.getTopPixel(); + int adjustedMouseY = mouseY + verticalScrollOffset; + int lineHeight = m_Text.getLineHeight(); - int screenLine = mouseY / lineHeight; - int line = topLine + screenLine; + int line = adjustedMouseY / lineHeight; - if (line > m_Text.getLineCount()) + if (line > m_Text.getLineCount()) { + System.err.println("WARNING: Right-clicked line number is greater than " + + "the number of lines in the text widget."); return -1; + } return line; } @@ -1083,8 +1087,7 @@ public void makeCharPosVisible(int charPos) ********************************************************************************************/ public int getCharacterPosition(String text, int mouseX) { - // The only way to compute this I can think of to compute which - // character was clicked on + // The only way to compute this I can think of // is to generate each substring in turn and check its length against // the point. // When we reach the correct length of string we've found the character. diff --git a/Java/Debugger/src/edu/umich/soar/debugger/modules/FoldingTextView.java b/Java/Debugger/src/edu/umich/soar/debugger/modules/FoldingTextView.java index 5a6b58b1ea..e36d64faf8 100644 --- a/Java/Debugger/src/edu/umich/soar/debugger/modules/FoldingTextView.java +++ b/Java/Debugger/src/edu/umich/soar/debugger/modules/FoldingTextView.java @@ -751,11 +751,13 @@ public boolean find(String text, boolean searchDown, boolean matchCase, protected ParseSelectedText.SelectedObject getCurrentSelection(int mouseX, int mouseY) { - // Switchfrom screen coords to coords based on the text window + // Switch from screen coords to coords based on the text window Point pt = m_FoldingText.getTextWindow().toControl(mouseX, mouseY); mouseX = pt.x; mouseY = pt.y; +// System.out.println("Received right-click at (" + mouseX + "," + mouseY + ")"); + int line = m_FoldingText.getLine(mouseY); if (line == -1) return null;