Skip to content

'Find in reference' will work even if no text has been selected. #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
hardware/arduino/bootloaders/caterina_LUFA/.dep/
.gitignore
build/windows/work/
build/windows/work/
build/linux/work/
71 changes: 50 additions & 21 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import processing.app.tools.*;
import processing.core.*;
import static processing.app.I18n._;
import static processing.app.ObjectUtil.defaultIfEmpty;

import java.awt.*;
import java.awt.datatransfer.*;
Expand Down Expand Up @@ -1073,9 +1074,10 @@ public void actionPerformed(ActionEvent e) {
item = newJMenuItemShift(_("Find in Reference"), 'F');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (textarea.isSelectionActive()) {
handleFindReference();
}
// if (textarea.isSelectionActive()) {
// handleFindReference();
// }
handleFindReference();
}
});
menu.add(item);
Expand Down Expand Up @@ -1809,24 +1811,51 @@ protected void handleIndentOutdent(boolean indent) {
}


protected void handleFindReference() {
String text = textarea.getSelectedText().trim();

if (text.length() == 0) {
statusNotice(_("First select a word to find in the reference."));

} else {
String referenceFile = PdeKeywords.getReference(text);
//System.out.println("reference file is " + referenceFile);
if (referenceFile == null) {
statusNotice(
I18n.format(_("No reference available for \"{0}\""), text)
);
} else {
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
}
}
}
protected void handleFindReference() {
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();
}

String referenceFile = PdeKeywords.getReference(text);
if (referenceFile == null) {
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
} else {
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
}
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Expand Down
3 changes: 0 additions & 3 deletions app/src/processing/app/Resources_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@
#: Editor.java:1255
!Use\ Selection\ For\ Find=

#: Editor.java:1816
!First\ select\ a\ word\ to\ find\ in\ the\ reference.=

#: Editor.java:1823
#, java-format
!No\ reference\ available\ for\ "{0}"=
Expand Down