Skip to content

Commit

Permalink
Account for half-scrolled lines in right-click
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garfieldnate committed Sep 27, 2024
1 parent 67eb06d commit 3bbee22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions Java/Debugger/src/edu/umich/soar/debugger/helpers/FoldingText.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3bbee22

Please sign in to comment.