GT-2716 - Decompiler - Fixed 'Find' highlight ghosts

This commit is contained in:
dragonmacher 2019-04-01 18:25:05 -04:00
parent 7179c6de81
commit 1626d2ee1b
11 changed files with 94 additions and 39 deletions

View file

@ -1,5 +1,6 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -197,4 +198,8 @@ public class ClangTextField extends WrappingVerticalLayoutTextField {
return lineNumberFieldElement.getStringWidth();
}
public int getLineNumber() {
String text = lineNumberFieldElement.getText().trim();
return Integer.parseInt(text);
}
}

View file

@ -1,5 +1,6 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +38,7 @@ import docking.widgets.indexedscrollpane.IndexedScrollPane;
import ghidra.app.decompiler.*;
import ghidra.app.decompiler.component.hover.DecompilerHoverService;
import ghidra.app.plugin.core.decompile.DecompileClipboardProvider;
import ghidra.app.plugin.core.decompile.actions.FieldBasedSearchLocation;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
@ -175,6 +177,9 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
if (clipboard != null) {
clipboard.selectionChanged(null);
}
// don't highlight search results across functions
currentSearchLocation = null;
}
private void setLocation(DecompileData oldData, DecompileData newData) {
@ -696,9 +701,27 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
}
class SearchHighlightFactory implements HighlightFactory {
@Override
public Highlight[] getHighlights(String text, int cursorTextOffset) {
if (currentSearchLocation == null || cursorTextOffset == -1) {
// the search highlight needs the Field in order to work correctly
return new Highlight[0];
}
@Override
public Highlight[] getHighlights(Field field, String text, int cursorTextOffset) {
if (currentSearchLocation == null) {
return new Highlight[0];
}
ClangTextField cField = (ClangTextField) field;
int highlightLine = cField.getLineNumber();
FieldLocation searchCursorLocation =
((FieldBasedSearchLocation) currentSearchLocation).getFieldLocation();
int searchLineNumber = searchCursorLocation.getIndex().intValue() + 1;
if (highlightLine != searchLineNumber) {
// only highlight the match on the actual line
return new Highlight[0];
}

View file

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -39,4 +38,9 @@ public class FieldBasedSearchLocation extends SearchLocation {
public CursorPosition getCursorPosition() {
return new DecompilerCursorPosition(fieldLocation);
}
@Override
protected String fieldsToString() {
return super.fieldsToString() + ", fieldLocation=" + fieldLocation;
}
}

View file

@ -1,5 +1,6 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -77,13 +78,20 @@ public class FindAction extends DockingAction {
if (text != null) {
dialog.setSearchText(text);
}
// show over the root frame, so the user can still see the Decompiler window
tool.showDialog(dialog);
}
protected FindDialog getFindDialog() {
if (findDialog == null) {
findDialog = new FindDialog("Decompiler Find Text", new DecompilerSearcher());
findDialog = new FindDialog("Decompiler Find Text", new DecompilerSearcher()) {
@Override
protected void dialogClosed() {
// clear the search results when the dialog is closed
decompilerPanel.setSearchResults(null);
}
};
findDialog.setHelpLocation(new HelpLocation("DecompilePlugin", "Find"));
}
return findDialog;