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,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.
@ -60,6 +59,10 @@ public class SearchLocation {
@Override
public String toString() {
return searchText + "[start=" + startIndexInclusive + ", end=" + endIndexInclusive + "]";
return searchText + "[" + fieldsToString() + "]";
}
protected String fieldsToString() {
return startIndexInclusive + ", end=" + endIndexInclusive;
}
}

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.
@ -129,8 +128,8 @@ public class ClippingTextField implements TextField {
int x = findX(col) + startX;
return new Rectangle(x, -textElement.getHeightAbove(), 2, textElement.getHeightAbove() +
textElement.getHeightBelow());
return new Rectangle(x, -textElement.getHeightAbove(), 2,
textElement.getHeightAbove() + textElement.getHeightBelow());
}
/**
@ -315,7 +314,7 @@ public class ClippingTextField implements TextField {
if (cursorLoc != null) {
cursorTextOffset = screenLocationToTextOffset(cursorLoc.row(), cursorLoc.col());
}
paintHighlights(g, hlFactory.getHighlights(getString(), cursorTextOffset));
paintHighlights(g, hlFactory.getHighlights(this, getString(), cursorTextOffset));
}
protected void paintSelection(Graphics g, FieldBackgroundColorManager colorManager, int row,
@ -344,10 +343,10 @@ public class ClippingTextField implements TextField {
}
protected void paintHighlights(Graphics g, Highlight[] highlights) {
for (int i = 0; i < highlights.length; i++) {
int startCol = Math.max(highlights[i].getStart(), 0);
int endCol = Math.min(highlights[i].getEnd(), getString().length());
Color c = highlights[i].getColor();
for (Highlight highlight : highlights) {
int startCol = Math.max(highlight.getStart(), 0);
int endCol = Math.min(highlight.getEnd(), getString().length());
Color c = highlight.getColor();
if (endCol >= startCol) {
int start = findX(startCol);
int end = findX(endCol + 1);

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.
@ -142,8 +141,8 @@ public class ReverseClippingTextField implements TextField {
int x = findX(col) + textStartX;
return new Rectangle(x, -textElement.getHeightAbove(), 2, textElement.getHeightAbove() +
textElement.getHeightBelow());
return new Rectangle(x, -textElement.getHeightAbove(), 2,
textElement.getHeightAbove() + textElement.getHeightBelow());
}
/**
@ -336,8 +335,7 @@ public class ReverseClippingTextField implements TextField {
private void paintDots(Graphics g, int x) {
int pos = 1; // skip one pixel
for (int i = 0; i < 3; i++) {
if (pos < DOT_DOT_DOT_WIDTH - 2) { // don't paint too close to next
// field.
if (pos < DOT_DOT_DOT_WIDTH - 2) { // don't paint too close to next field
g.drawRect(x + pos, -2, 1, 1);
pos += 4; // add in size of dot and padding
}
@ -349,14 +347,14 @@ public class ReverseClippingTextField implements TextField {
if (cursorLoc != null) {
cursorTextOffset = screenLocationToTextOffset(cursorLoc.row(), cursorLoc.col());
}
paintHighlights(g, hlFactory.getHighlights(getString(), cursorTextOffset));
paintHighlights(g, hlFactory.getHighlights(this, getString(), cursorTextOffset));
}
protected void paintHighlights(Graphics g, Highlight[] highlights) {
for (int i = 0; i < highlights.length; i++) {
int startCol = Math.max(highlights[i].getStart() - startingCharIndex, 0);
int endCol = Math.min(highlights[i].getEnd() - startingCharIndex, getString().length());
Color c = highlights[i].getColor();
for (Highlight highlight : highlights) {
int startCol = Math.max(highlight.getStart() - startingCharIndex, 0);
int endCol = Math.min(highlight.getEnd() - startingCharIndex, getString().length());
Color c = highlight.getColor();
if (endCol >= startCol) {
int start = findX(startCol);
int end = findX(endCol + 1);

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.
@ -202,7 +201,7 @@ public class SimpleTextField implements Field {
public void paint(JComponent c, Graphics g, PaintContext context,
FieldBackgroundColorManager colorManager, RowColLocation cursorLoc, int rowHeight) {
paintSelection(g, colorManager, 0);
paintHighlights(g, hlFactory.getHighlights(text, -1));
paintHighlights(g, hlFactory.getHighlights(this, text, -1));
g.setFont(metrics.getFont());
if (foregroundColor == null) {
foregroundColor = context.getForeground();
@ -226,10 +225,10 @@ public class SimpleTextField implements Field {
}
protected void paintHighlights(Graphics g, Highlight[] highlights) {
for (int i = 0; i < highlights.length; i++) {
int startCol = Math.max(highlights[i].getStart(), 0);
int endCol = Math.min(highlights[i].getEnd(), text.length());
Color c = highlights[i].getColor();
for (Highlight highlight : highlights) {
int startCol = Math.max(highlight.getStart(), 0);
int endCol = Math.min(highlight.getEnd(), text.length());
Color c = highlight.getColor();
if (endCol >= startCol) {
int start = findX(startCol);
int end = findX(endCol + 1);

View file

@ -268,7 +268,7 @@ public class VerticalLayoutTextField implements TextField {
cursorRow = cursorLoc.row();
}
Highlight[] highlights = hlFactory.getHighlights(getText(), cursorTextOffset);
Highlight[] highlights = hlFactory.getHighlights(this, getText(), cursorTextOffset);
int columns = 0;
int n = subFields.size();
Color fieldBackgroundColor = colorManager.getBackgroundColor();

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.
@ -16,13 +15,30 @@
*/
package docking.widgets.fieldpanel.support;
import docking.widgets.fieldpanel.field.Field;
public interface HighlightFactory {
/**
* Returns the highlights for the given text.
* @param text the text to be considered for highlighting.
* Returns the highlights for the given text
*
* @param text the text to be considered for highlighting
* @param cursorTextOffset the position in the given text of the cursor. A -1 indicates the
* cursor is not in this field.
* @return an array of highlights to be rendered.
* cursor is not in this field.
* @return an array of highlights to be rendered
*/
public Highlight[] getHighlights(String text, int cursorTextOffset);
/**
* Returns the highlights for the given text
*
* @param field the field that is requesting the highlight
* @param text the text to be considered for highlighting
* @param cursorTextOffset the position in the given text of the cursor. A -1 indicates the
* cursor is not in this field.
* @return an array of highlights to be rendered
*/
public default Highlight[] getHighlights(Field field, String text, int cursorTextOffset) {
return getHighlights(text, cursorTextOffset);
}
}