Skip to content

Commit 2ca5d3e

Browse files
committed
- Moved code guessing current keyword in its function
- Find-in-reference disabled in right-click popup menu unless appropriate text is selected (arduino#1014)
1 parent 222d51e commit 2ca5d3e

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

app/src/processing/app/Editor.java

+28-23
Original file line numberDiff line numberDiff line change
@@ -1809,44 +1809,50 @@ protected void handleIndentOutdent(boolean indent) {
18091809
stopCompoundEdit();
18101810
}
18111811

1812-
1813-
protected void handleFindReference() {
1812+
protected String getCurrentKeyword() {
18141813
String text = "";
1815-
if( textarea.getSelectedText() != null )
1814+
if (textarea.getSelectedText() != null)
18161815
text = textarea.getSelectedText().trim();
1817-
1816+
18181817
try {
18191818
int current = textarea.getCaretPosition();
18201819
int startOffset = 0;
18211820
int endIndex = current;
1822-
String tmp = textarea.getDocument().getText(current,1);
1823-
// TODO probably a regexp that matches Arduino lang special chars already exists.
1821+
String tmp = textarea.getDocument().getText(current, 1);
1822+
// TODO probably a regexp that matches Arduino lang special chars
1823+
// already exists.
18241824
String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";
1825-
1826-
while(!tmp.matches(regexp)) {
1825+
1826+
while (!tmp.matches(regexp)) {
18271827
endIndex++;
1828-
tmp = textarea.getDocument().getText(endIndex,1);
1828+
tmp = textarea.getDocument().getText(endIndex, 1);
18291829
}
18301830
// For some reason document index start at 2.
1831-
//if( current - start < 2 ) return;
1832-
1831+
// if( current - start < 2 ) return;
1832+
18331833
tmp = "";
1834-
while(!tmp.matches(regexp)) {
1834+
while (!tmp.matches(regexp)) {
18351835
startOffset++;
1836-
if( current - startOffset < 0) {
1836+
if (current - startOffset < 0) {
18371837
tmp = textarea.getDocument().getText(0, 1);
18381838
break;
1839-
}
1840-
else
1839+
} else
18411840
tmp = textarea.getDocument().getText(current - startOffset, 1);
18421841
}
18431842
startOffset--;
1844-
1843+
18451844
int length = endIndex - current + startOffset;
18461845
text = textarea.getDocument().getText(current - startOffset, length);
1847-
} catch (BadLocationException bl ) {
1848-
bl.printStackTrace();
1846+
1847+
} catch (BadLocationException bl) {
1848+
bl.printStackTrace();
1849+
} finally {
1850+
return text;
18491851
}
1852+
}
1853+
1854+
protected void handleFindReference() {
1855+
String text = getCurrentKeyword();
18501856

18511857
String referenceFile = PdeKeywords.getReference(text);
18521858
if (referenceFile == null) {
@@ -2781,16 +2787,15 @@ public void show(Component component, int x, int y) {
27812787
copyItem.setEnabled(true);
27822788
discourseItem.setEnabled(true);
27832789

2784-
String sel = textarea.getSelectedText().trim();
2785-
referenceFile = PdeKeywords.getReference(sel);
2786-
referenceItem.setEnabled(referenceFile != null);
2787-
27882790
} else {
27892791
cutItem.setEnabled(false);
27902792
copyItem.setEnabled(false);
27912793
discourseItem.setEnabled(false);
2792-
referenceItem.setEnabled(false);
27932794
}
2795+
2796+
referenceFile = PdeKeywords.getReference(getCurrentKeyword());
2797+
referenceItem.setEnabled(referenceFile != null);
2798+
27942799
super.show(component, x, y);
27952800
}
27962801
}

0 commit comments

Comments
 (0)