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;