@@ -1809,44 +1809,50 @@ protected void handleIndentOutdent(boolean indent) {
1809
1809
stopCompoundEdit ();
1810
1810
}
1811
1811
1812
-
1813
- protected void handleFindReference () {
1812
+ protected String getCurrentKeyword () {
1814
1813
String text = "" ;
1815
- if ( textarea .getSelectedText () != null )
1814
+ if ( textarea .getSelectedText () != null )
1816
1815
text = textarea .getSelectedText ().trim ();
1817
-
1816
+
1818
1817
try {
1819
1818
int current = textarea .getCaretPosition ();
1820
1819
int startOffset = 0 ;
1821
1820
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.
1824
1824
String regexp = "[\\ s\\ n();\\ \\ .!='\\ [\\ ]{}]" ;
1825
-
1826
- while (!tmp .matches (regexp )) {
1825
+
1826
+ while (!tmp .matches (regexp )) {
1827
1827
endIndex ++;
1828
- tmp = textarea .getDocument ().getText (endIndex ,1 );
1828
+ tmp = textarea .getDocument ().getText (endIndex , 1 );
1829
1829
}
1830
1830
// For some reason document index start at 2.
1831
- //if( current - start < 2 ) return;
1832
-
1831
+ // if( current - start < 2 ) return;
1832
+
1833
1833
tmp = "" ;
1834
- while (!tmp .matches (regexp )) {
1834
+ while (!tmp .matches (regexp )) {
1835
1835
startOffset ++;
1836
- if ( current - startOffset < 0 ) {
1836
+ if ( current - startOffset < 0 ) {
1837
1837
tmp = textarea .getDocument ().getText (0 , 1 );
1838
1838
break ;
1839
- }
1840
- else
1839
+ } else
1841
1840
tmp = textarea .getDocument ().getText (current - startOffset , 1 );
1842
1841
}
1843
1842
startOffset --;
1844
-
1843
+
1845
1844
int length = endIndex - current + startOffset ;
1846
1845
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 ;
1849
1851
}
1852
+ }
1853
+
1854
+ protected void handleFindReference () {
1855
+ String text = getCurrentKeyword ();
1850
1856
1851
1857
String referenceFile = PdeKeywords .getReference (text );
1852
1858
if (referenceFile == null ) {
@@ -2781,16 +2787,15 @@ public void show(Component component, int x, int y) {
2781
2787
copyItem .setEnabled (true );
2782
2788
discourseItem .setEnabled (true );
2783
2789
2784
- String sel = textarea .getSelectedText ().trim ();
2785
- referenceFile = PdeKeywords .getReference (sel );
2786
- referenceItem .setEnabled (referenceFile != null );
2787
-
2788
2790
} else {
2789
2791
cutItem .setEnabled (false );
2790
2792
copyItem .setEnabled (false );
2791
2793
discourseItem .setEnabled (false );
2792
- referenceItem .setEnabled (false );
2793
2794
}
2795
+
2796
+ referenceFile = PdeKeywords .getReference (getCurrentKeyword ());
2797
+ referenceItem .setEnabled (referenceFile != null );
2798
+
2794
2799
super .show (component , x , y );
2795
2800
}
2796
2801
}
0 commit comments