mirror of https://github.com/noisymime/Arduino.git
The 'find in reference' will look for current token and open
respective doc page if exists.
This commit is contained in:
parent
1691367fd9
commit
4a09287c45
|
@ -1812,11 +1812,43 @@ public class Editor extends JFrame implements RunnerListener {
|
|||
|
||||
|
||||
protected void handleFindReference() {
|
||||
String text = defaultIfEmpty(textarea.getSelectedText(), "").trim();
|
||||
String text = "";
|
||||
if( textarea.getSelectedText() != null )
|
||||
text = textarea.getSelectedText().trim();
|
||||
|
||||
try {
|
||||
int current = textarea.getCaretPosition();
|
||||
int startOffset = 0;
|
||||
int endIndex = current;
|
||||
String tmp = textarea.getDocument().getText(current,1);
|
||||
// TODO probably a regexp that matches Arduino lang special chars already exists.
|
||||
String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";
|
||||
|
||||
while(!tmp.matches(regexp)) {
|
||||
endIndex++;
|
||||
tmp = textarea.getDocument().getText(endIndex,1);
|
||||
}
|
||||
// For some reason document index start at 2.
|
||||
//if( current - start < 2 ) return;
|
||||
|
||||
tmp = "";
|
||||
while(!tmp.matches(regexp)) {
|
||||
startOffset++;
|
||||
if( current - startOffset < 0) {
|
||||
tmp = textarea.getDocument().getText(0, 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
tmp = textarea.getDocument().getText(current - startOffset, 1);
|
||||
}
|
||||
startOffset--;
|
||||
|
||||
int length = endIndex - current + startOffset;
|
||||
text = textarea.getDocument().getText(current - startOffset, length);
|
||||
} catch (BadLocationException bl ) {
|
||||
bl.printStackTrace();
|
||||
}
|
||||
|
||||
if (text.length() == 0) {
|
||||
Base.showReference();
|
||||
} else {
|
||||
String referenceFile = PdeKeywords.getReference(text);
|
||||
if (referenceFile == null) {
|
||||
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
|
||||
|
@ -1824,7 +1856,6 @@ public class Editor extends JFrame implements RunnerListener {
|
|||
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
|
Loading…
Reference in New Issue