use of org.fife.ui.rtextarea.SearchResult in project jadx by skylot.
the class SearchBar method search.
private void search(int direction) {
String searchText = searchField.getText();
if (searchText == null || searchText.length() == 0 || rTextArea.getText() == null) {
return;
}
boolean forward = direction >= 0;
boolean matchCase = matchCaseCB.isSelected();
boolean regex = regexCB.isSelected();
boolean wholeWord = wholeWordCB.isSelected();
SearchContext context = new SearchContext();
context.setSearchFor(searchText);
context.setMatchCase(matchCase);
context.setRegularExpression(regex);
context.setSearchForward(forward);
context.setWholeWord(wholeWord);
context.setMarkAll(markAllCB.isSelected());
// TODO hack: move cursor before previous search for not jump to next occurrence
if (direction == 0 && !COLOR_BG_ERROR.equals(searchField.getBackground())) {
try {
int caretPos = rTextArea.getCaretPosition();
int lineNum = rTextArea.getLineOfOffset(caretPos) - 1;
if (lineNum > 1) {
rTextArea.setCaretPosition(rTextArea.getLineStartOffset(lineNum));
}
} catch (BadLocationException e) {
LOG.error("Caret move error", e);
}
}
SearchResult result = SearchEngine.find(rTextArea, context);
if (!result.wasFound()) {
int pos = SearchEngine.getNextMatchPos(searchText, rTextArea.getText(), forward, matchCase, wholeWord);
if (pos != -1) {
rTextArea.setCaretPosition(forward ? 0 : rTextArea.getDocument().getLength() - 1);
search(direction);
searchField.setBackground(COLOR_BG_WARN);
return;
}
searchField.setBackground(COLOR_BG_ERROR);
} else {
searchField.setBackground(COLOR_BG_NORMAL);
}
}
Aggregations