Skip to content

Commit cff42b9

Browse files
committed
ASTGen: remove lastClickedWord
1 parent 7255290 commit cff42b9

3 files changed

Lines changed: 10 additions & 111 deletions

File tree

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,16 @@ public void mousePressed(MouseEvent event) {
24522452
// // Windows fires the popup trigger on release (see mouseReleased() below)(
24532453
// if (!Base.isWindows()) {
24542454
// if (event.isPopupTrigger() && (popup != null)) {
2455+
2456+
// If user right-clicked inside the selection, preserve it;
2457+
// move caret to click offset otherwise
2458+
int offset = xyToOffset(event.getX(), event.getY());
2459+
int selectionStart = getSelectionStart();
2460+
int selectionStop = getSelectionStop();
2461+
if (offset < selectionStart || offset >= selectionStop) {
2462+
select(offset, offset);
2463+
}
2464+
24552465
popup.show(painter, event.getX(), event.getY());
24562466
return;
24572467
// }

java/src/processing/mode/java/pdex/ASTGenerator.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,22 +1185,6 @@ public void handleShowUsage(int tabIndex, int startTabOffset, int stopTabOffset)
11851185
handleShowUsage(binding);
11861186
}
11871187

1188-
protected int lastClickedTab = 0;
1189-
protected int lastClickedOffset = 0;
1190-
protected String lastClickedWord = null;
1191-
1192-
public String getLastClickedWord() {
1193-
return lastClickedWord;
1194-
}
1195-
1196-
public void setLastClickedWord(int tabIndex, int offset, String lastClickedWord) {
1197-
Messages.log("* setLastClickedWord");
1198-
this.lastClickedTab = tabIndex;
1199-
this.lastClickedOffset = offset;
1200-
this.lastClickedWord = lastClickedWord;
1201-
log("Last clicked: " + lastClickedWord);
1202-
}
1203-
12041188

12051189
public void handleShowUsage(IBinding binding) {
12061190
PreprocessedSketch ps = errorCheckerService.latestResult;
@@ -1212,8 +1196,6 @@ public void handleShowUsage(IBinding binding) {
12121196
List<SimpleName> occurrences = findAllOccurrences(ps.compilationUnit, bindingKey);
12131197
if (occurrences == null) return;
12141198

1215-
lastClickedWord = null;
1216-
12171199
// Send to gui
12181200
EventQueue.invokeLater(() -> gui.handleShowUsage(binding, occurrences));
12191201
}
@@ -2571,11 +2553,6 @@ public void scrollToDeclaration(int tabIndex, int offset) {
25712553
}
25722554

25732555

2574-
private String getSelectedText() {
2575-
return editor.getTextArea().getSelectedText();
2576-
}
2577-
2578-
25792556

25802557
/// GUI ----------------------------------------------------------------------
25812558

java/src/processing/mode/java/pdex/JavaTextArea.java

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public JavaTextArea(TextAreaDefaults defaults, JavaEditor editor) {
7575
super(defaults, new JavaInputHandler(editor));
7676
this.editor = editor;
7777

78-
// handle right click on a word
79-
painter.addMouseListener(rightClickMouseAdapter);
80-
8178
// change cursor to pointer in the gutter area
8279
painter.addMouseMotionListener(gutterCursorMouseAdapter);
8380

@@ -258,77 +255,6 @@ private void prepareSuggestions(final KeyEvent evt) {
258255
}
259256

260257

261-
/**
262-
* Retrieves the word on which the mouse pointer is present
263-
* @param evt - the MouseEvent which triggered this method
264-
*/
265-
private String fetchPhrase(MouseEvent evt) {
266-
Messages.log("--handle Mouse Right Click--");
267-
int off = xyToOffset(evt.getX(), evt.getY());
268-
if (off < 0)
269-
return null;
270-
int line = getLineOfOffset(off);
271-
if (line < 0)
272-
return null;
273-
String s = getLineText(line);
274-
if (s == null)
275-
return null;
276-
else if (s.length() == 0)
277-
return null;
278-
else {
279-
int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
280-
Messages.log("x=" + x);
281-
if (x < 0 || x >= s.length())
282-
return null;
283-
String word = s.charAt(x) + "";
284-
if (s.charAt(x) == ' ')
285-
return null;
286-
if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s
287-
.charAt(x) == '$'))
288-
return null;
289-
int i = 0;
290-
while (true) {
291-
i++;
292-
if (x1 >= 0 && x1 < s.length()) {
293-
if (Character.isLetter(s.charAt(x1)) || s.charAt(x1) == '_') {
294-
word = s.charAt(x1--) + word;
295-
} else
296-
x1 = -1;
297-
} else
298-
x1 = -1;
299-
300-
if (x2 >= 0 && x2 < s.length()) {
301-
if (Character.isLetterOrDigit(s.charAt(x2)) || s.charAt(x2) == '_'
302-
|| s.charAt(x2) == '$')
303-
word = word + s.charAt(x2++);
304-
else
305-
x2 = -1;
306-
} else
307-
x2 = -1;
308-
309-
if (x1 < 0 && x2 < 0)
310-
break;
311-
if (i > 200) {
312-
// time out!
313-
break;
314-
}
315-
}
316-
if (Character.isDigit(word.charAt(0))) {
317-
return null;
318-
}
319-
Messages.log("Mouse click, word: " + word.trim());
320-
ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator();
321-
322-
int tabIndex = editor.getSketch().getCurrentCodeIndex();
323-
324-
synchronized (astGenerator) {
325-
astGenerator.setLastClickedWord(tabIndex, off, word);
326-
}
327-
return word.trim();
328-
}
329-
}
330-
331-
332258
SwingWorker<Void, Void> suggestionWorker = null;
333259

334260
volatile boolean suggestionRunning = false;
@@ -708,20 +634,6 @@ public int xToOffset(int line, int x) {
708634
}
709635

710636

711-
/**
712-
* Fetches word under the cursor on right click
713-
*/
714-
protected final MouseAdapter rightClickMouseAdapter = new MouseAdapter() {
715-
@Override
716-
public void mousePressed(MouseEvent me) {
717-
if (me.getButton() == MouseEvent.BUTTON3 &&
718-
!editor.hasJavaTabs()) { // tooltips, etc disabled for java tabs
719-
fetchPhrase(me);
720-
}
721-
}
722-
};
723-
724-
725637
/**
726638
* Sets default cursor (instead of text cursor) in the gutter area.
727639
*/

0 commit comments

Comments
 (0)