From 8a5297b33c9877f3b3e71d0445116f522183c815 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Fri, 22 Apr 2016 10:51:26 +0200 Subject: [PATCH] ASTGen: remove lastClickedWord --- .../processing/app/syntax/JEditTextArea.java | 10 +++ .../mode/java/pdex/ASTGenerator.java | 23 ----- .../mode/java/pdex/JavaTextArea.java | 88 ------------------- 3 files changed, 10 insertions(+), 111 deletions(-) diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index 5fb7392db..eef1f79d6 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -2452,6 +2452,16 @@ public class JEditTextArea extends JComponent // // Windows fires the popup trigger on release (see mouseReleased() below)( // if (!Base.isWindows()) { // if (event.isPopupTrigger() && (popup != null)) { + + // If user right-clicked inside the selection, preserve it; + // move caret to click offset otherwise + int offset = xyToOffset(event.getX(), event.getY()); + int selectionStart = getSelectionStart(); + int selectionStop = getSelectionStop(); + if (offset < selectionStart || offset >= selectionStop) { + select(offset, offset); + } + popup.show(painter, event.getX(), event.getY()); return; // } diff --git a/java/src/processing/mode/java/pdex/ASTGenerator.java b/java/src/processing/mode/java/pdex/ASTGenerator.java index 94f12f27b..75e67d5db 100644 --- a/java/src/processing/mode/java/pdex/ASTGenerator.java +++ b/java/src/processing/mode/java/pdex/ASTGenerator.java @@ -1185,22 +1185,6 @@ public class ASTGenerator { handleShowUsage(binding); } - protected int lastClickedTab = 0; - protected int lastClickedOffset = 0; - protected String lastClickedWord = null; - - public String getLastClickedWord() { - return lastClickedWord; - } - - public void setLastClickedWord(int tabIndex, int offset, String lastClickedWord) { - Messages.log("* setLastClickedWord"); - this.lastClickedTab = tabIndex; - this.lastClickedOffset = offset; - this.lastClickedWord = lastClickedWord; - log("Last clicked: " + lastClickedWord); - } - public void handleShowUsage(IBinding binding) { PreprocessedSketch ps = errorCheckerService.latestResult; @@ -1212,8 +1196,6 @@ public class ASTGenerator { List occurrences = findAllOccurrences(ps.compilationUnit, bindingKey); if (occurrences == null) return; - lastClickedWord = null; - // Send to gui EventQueue.invokeLater(() -> gui.handleShowUsage(binding, occurrences)); } @@ -2571,11 +2553,6 @@ public class ASTGenerator { } - private String getSelectedText() { - return editor.getTextArea().getSelectedText(); - } - - /// GUI ---------------------------------------------------------------------- diff --git a/java/src/processing/mode/java/pdex/JavaTextArea.java b/java/src/processing/mode/java/pdex/JavaTextArea.java index 74b39f85d..e068437bf 100644 --- a/java/src/processing/mode/java/pdex/JavaTextArea.java +++ b/java/src/processing/mode/java/pdex/JavaTextArea.java @@ -75,9 +75,6 @@ public class JavaTextArea extends JEditTextArea { super(defaults, new JavaInputHandler(editor)); this.editor = editor; - // handle right click on a word - painter.addMouseListener(rightClickMouseAdapter); - // change cursor to pointer in the gutter area painter.addMouseMotionListener(gutterCursorMouseAdapter); @@ -258,77 +255,6 @@ public class JavaTextArea extends JEditTextArea { } - /** - * Retrieves the word on which the mouse pointer is present - * @param evt - the MouseEvent which triggered this method - */ - private String fetchPhrase(MouseEvent evt) { - Messages.log("--handle Mouse Right Click--"); - int off = xyToOffset(evt.getX(), evt.getY()); - if (off < 0) - return null; - int line = getLineOfOffset(off); - if (line < 0) - return null; - String s = getLineText(line); - if (s == null) - return null; - else if (s.length() == 0) - return null; - else { - int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1; - Messages.log("x=" + x); - if (x < 0 || x >= s.length()) - return null; - String word = s.charAt(x) + ""; - if (s.charAt(x) == ' ') - return null; - if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s - .charAt(x) == '$')) - return null; - int i = 0; - while (true) { - i++; - if (x1 >= 0 && x1 < s.length()) { - if (Character.isLetter(s.charAt(x1)) || s.charAt(x1) == '_') { - word = s.charAt(x1--) + word; - } else - x1 = -1; - } else - x1 = -1; - - if (x2 >= 0 && x2 < s.length()) { - if (Character.isLetterOrDigit(s.charAt(x2)) || s.charAt(x2) == '_' - || s.charAt(x2) == '$') - word = word + s.charAt(x2++); - else - x2 = -1; - } else - x2 = -1; - - if (x1 < 0 && x2 < 0) - break; - if (i > 200) { - // time out! - break; - } - } - if (Character.isDigit(word.charAt(0))) { - return null; - } - Messages.log("Mouse click, word: " + word.trim()); - ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator(); - - int tabIndex = editor.getSketch().getCurrentCodeIndex(); - - synchronized (astGenerator) { - astGenerator.setLastClickedWord(tabIndex, off, word); - } - return word.trim(); - } - } - - SwingWorker suggestionWorker = null; volatile boolean suggestionRunning = false; @@ -708,20 +634,6 @@ public class JavaTextArea extends JEditTextArea { } - /** - * Fetches word under the cursor on right click - */ - protected final MouseAdapter rightClickMouseAdapter = new MouseAdapter() { - @Override - public void mousePressed(MouseEvent me) { - if (me.getButton() == MouseEvent.BUTTON3 && - !editor.hasJavaTabs()) { // tooltips, etc disabled for java tabs - fetchPhrase(me); - } - } - }; - - /** * Sets default cursor (instead of text cursor) in the gutter area. */