mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Double-click now opens URL (right-click still shows "Open URL" in popup
menù).
This commit is contained in:
parent
303b2e5103
commit
88794ec1d6
@ -2739,22 +2739,13 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
add(referenceItem);
|
||||
}
|
||||
|
||||
private boolean clickedURL(String line, int offset) {
|
||||
String[] parse = SyntaxUtilities.parseCommentUrls(line);
|
||||
if (parse==null)
|
||||
return false;
|
||||
int start = parse[0].length();
|
||||
int stop = start + parse[1].length();
|
||||
if (offset<start|| offset>stop+2)
|
||||
return false;
|
||||
clickedURL = parse[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
// if no text is selected, disable copy and cut menu items
|
||||
public void show(Component component, int x, int y) {
|
||||
int line = textarea.getLineOfOffset(textarea.xyToOffset(x, y));
|
||||
if (clickedURL(textarea.getLineText(line), textarea.xToOffset(line, x))) {
|
||||
int lineNo = textarea.getLineOfOffset(textarea.xyToOffset(x, y));
|
||||
int offset = textarea.xToOffset(lineNo, x);
|
||||
String line = textarea.getLineText(lineNo);
|
||||
clickedURL = textarea.checkClickedURL(line, offset);
|
||||
if (clickedURL != null) {
|
||||
openURLItem.setVisible(true);
|
||||
openURLItemSeparator.setVisible(true);
|
||||
} else {
|
||||
|
@ -2045,6 +2045,17 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
}
|
||||
|
||||
public String checkClickedURL(String line, int offset) {
|
||||
String[] parse = SyntaxUtilities.parseCommentUrls(line);
|
||||
if (parse==null)
|
||||
return null;
|
||||
int start = parse[0].length();
|
||||
int stop = start + parse[1].length();
|
||||
if (offset<start|| offset>stop)
|
||||
return null;
|
||||
return parse[1];
|
||||
}
|
||||
|
||||
class MouseHandler extends MouseAdapter
|
||||
{
|
||||
public void mousePressed(MouseEvent evt)
|
||||
@ -2111,6 +2122,13 @@ public class JEditTextArea extends JComponent
|
||||
if (getLineLength(line) == 0)
|
||||
return;
|
||||
|
||||
// Check for click on urls
|
||||
String clickedURL = checkClickedURL(getLineText(line), offset);
|
||||
if (clickedURL != null) {
|
||||
Base.openURL(clickedURL);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int bracket = TextUtilities.findMatchingBracket(document,
|
||||
Math.max(0,dot - 1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user