From 06e61171752dcf6e66d6759431cf3ece0c2e2ff0 Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:59:51 -0600 Subject: [PATCH] Add ability to use 'CTRL' + LMB for go to action. --- .../gui/util/BytecodeViewPanelUpdater.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index cf6f73ebd..33e790481 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -46,8 +46,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Element; import java.awt.*; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; +import java.awt.event.*; import java.util.Objects; import java.util.regex.Matcher; @@ -434,6 +433,48 @@ else if (isPanelEditable && decompiler == Decompiler.KRAKATAU_DISASSEMBLER) bytecodeViewPanel.textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK), "goToAction"); bytecodeViewPanel.textArea.getActionMap().put("goToAction", new GoToAction(classFileContainer)); + bytecodeViewPanel.textArea.addMouseMotionListener(new MouseMotionAdapter() + { + @Override + public void mouseMoved(MouseEvent e) + { + if (e.isControlDown()) + { + RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); + Token token = textArea.viewToToken(e.getPoint()); + if (token != null) + { + String lexeme = token.getLexeme(); + if (classFileContainer.fieldMembers.containsKey(lexeme) || classFileContainer.methodMembers.containsKey(lexeme) + || classFileContainer.methodLocalMembers.containsKey(lexeme) || classFileContainer.methodParameterMembers.containsKey(lexeme) + || classFileContainer.classReferences.containsKey(lexeme)) + { + textArea.setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + } + } else + { + if (bytecodeViewPanel.textArea.getCursor().getType() != Cursor.TEXT_CURSOR) + { + bytecodeViewPanel.textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR)); + } + } + } + }); + + bytecodeViewPanel.textArea.addMouseListener(new MouseAdapter() + { + @Override + public void mouseClicked(MouseEvent e) + { + if (e.isControlDown()) + { + RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource(); + textArea.getActionMap().get("goToAction").actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, "goToAction")); + } + } + }); + markerCaretListener = new MarkerCaretListener(classContainerName); bytecodeViewPanel.textArea.addCaretListener(markerCaretListener); }