@@ -1812,17 +1812,48 @@ protected void handleIndentOutdent(boolean indent) {
18121812
18131813
18141814 protected void handleFindReference () {
1815- String text = defaultIfEmpty (textarea .getSelectedText (), "" ).trim ();
1816-
1817- if (text .length () == 0 ) {
1818- Base .showReference ();
1819- } else {
1820- String referenceFile = PdeKeywords .getReference (text );
1821- if (referenceFile == null ) {
1822- statusNotice (I18n .format (_ ("No reference available for \" {0}\" " ), text ));
1823- } else {
1824- Base .showReference (I18n .format (_ ("{0}.html" ), referenceFile ));
1815+ String text = "" ;
1816+ if ( textarea .getSelectedText () != null )
1817+ text = textarea .getSelectedText ().trim ();
1818+
1819+ try {
1820+ int current = textarea .getCaretPosition ();
1821+ int startOffset = 0 ;
1822+ int endIndex = current ;
1823+ String tmp = textarea .getDocument ().getText (current ,1 );
1824+ // TODO probably a regexp that matches Arduino lang special chars already exists.
1825+ String regexp = "[\\ s\\ n();\\ \\ .!='\\ [\\ ]{}]" ;
1826+
1827+ while (!tmp .matches (regexp )) {
1828+ endIndex ++;
1829+ tmp = textarea .getDocument ().getText (endIndex ,1 );
1830+ }
1831+ // For some reason document index start at 2.
1832+ //if( current - start < 2 ) return;
1833+
1834+ tmp = "" ;
1835+ while (!tmp .matches (regexp )) {
1836+ startOffset ++;
1837+ if ( current - startOffset < 0 ) {
1838+ tmp = textarea .getDocument ().getText (0 , 1 );
1839+ break ;
1840+ }
1841+ else
1842+ tmp = textarea .getDocument ().getText (current - startOffset , 1 );
18251843 }
1844+ startOffset --;
1845+
1846+ int length = endIndex - current + startOffset ;
1847+ text = textarea .getDocument ().getText (current - startOffset , length );
1848+ } catch (BadLocationException bl ) {
1849+ bl .printStackTrace ();
1850+ }
1851+
1852+ String referenceFile = PdeKeywords .getReference (text );
1853+ if (referenceFile == null ) {
1854+ statusNotice (I18n .format (_ ("No reference available for \" {0}\" " ), text ));
1855+ } else {
1856+ Base .showReference (I18n .format (_ ("{0}.html" ), referenceFile ));
18261857 }
18271858 }
18281859
0 commit comments