changes per review

This commit is contained in:
ghidravore 2020-05-01 16:30:08 -04:00
parent 5354ac64ba
commit 397a073bf6
2 changed files with 40 additions and 26 deletions

View file

@ -376,7 +376,7 @@ public class CodeBrowserClipboardProvider extends ByteCopier
try { try {
TextLayoutGraphics g = new TextLayoutGraphics(); TextLayoutGraphics g = new TextLayoutGraphics();
Rectangle rect = new Rectangle(2048, 2048); Rectangle rect = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE);
AddressRangeIterator rangeItr = addressSet.getAddressRanges(); AddressRangeIterator rangeItr = addressSet.getAddressRanges();
while (rangeItr.hasNext()) { while (rangeItr.hasNext()) {

View file

@ -208,7 +208,8 @@ public class VerticalLayoutTextField implements TextField {
@Override @Override
public void paint(JComponent c, Graphics g, PaintContext context, public void paint(JComponent c, Graphics g, PaintContext context,
Rectangle clip, FieldBackgroundColorManager colorManager, RowColLocation cursorLoc, int rowHeight) { Rectangle clip, FieldBackgroundColorManager colorManager, RowColLocation cursorLoc,
int rowHeight) {
if (context.isPrinting()) { if (context.isPrinting()) {
print(g, context); print(g, context);
return; return;
@ -224,48 +225,61 @@ public class VerticalLayoutTextField implements TextField {
Highlight[] highlights = hlFactory.getHighlights(this, getText(), cursorTextOffset); Highlight[] highlights = hlFactory.getHighlights(this, getText(), cursorTextOffset);
int columns = 0; int columns = 0;
int n = subFields.size(); int n = subFields.size();
// the graphics have been translated such that the first line of text's base line is
// at y=0 (So if we are not clipped, we will drawing from negative the fonts height above
// the baseline (-heightAbove) to rowHeight -heightAbove
int myStartY = -heightAbove;
int myEndY = myStartY + rowHeight;
int clipStartY = clip.y;
int clipEndY = clip.y + clip.height;
Color fieldBackgroundColor = colorManager.getBackgroundColor(); Color fieldBackgroundColor = colorManager.getBackgroundColor();
if (fieldBackgroundColor != null) { if (fieldBackgroundColor != null) {
g.setColor(fieldBackgroundColor); g.setColor(fieldBackgroundColor);
// restrict background rectangle to clipping rectangle // restrict background rectangle to clipping rectangle
int startY = Math.max(-heightAbove, clip.y); int startY = Math.max(myStartY, clipStartY);
int clippedHeight = Math.min(rowHeight - (startY + heightAbove), clip.height); int endY = Math.min(myEndY, clipEndY);
int clippedHeight = endY - startY;
g.fillRect(startX, startY, width, clippedHeight); g.fillRect(startX, startY, width, clippedHeight);
} }
int startY = myStartY;
int translatedY = 0; int translatedY = 0;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
ClippingTextField clippingField = (ClippingTextField) subFields.get(i); ClippingTextField subField = (ClippingTextField) subFields.get(i);
int subFieldHeight = clippingField.getHeight(); int subFieldHeight = subField.getHeight();
int startY = translatedY - heightAbove; int endY = startY + subFieldHeight;
// if this line is totally above the clip, skip it, but still must translate for next line // if past clipping region we are done
if (startY + subFieldHeight < clip.y) { if (startY > clipEndY) {
g.translate(0, subFieldHeight);
translatedY += subFieldHeight;
continue;
}
// if this line is totally below clip region, we are done
if (startY > clip.y + clip.height) {
break; break;
} }
// translate the highlights // if any part of the line is in the clip region, draw it
for (Highlight highlight : highlights) { if (endY >= clipStartY) {
highlight.setOffset(-columns); // translate the highlights
} for (Highlight highlight : highlights) {
clippingField.paintSelection(g, colorManager, i, rowHeight); highlight.setOffset(-columns);
clippingField.paintHighlights(g, highlights); }
clippingField.paintText(c, g, context); subField.paintSelection(g, colorManager, i, rowHeight);
if (cursorRow == i) { subField.paintHighlights(g, highlights);
clippingField.paintCursor(g, context.getCursorColor(), cursorLoc); subField.paintText(c, g, context);
if (cursorRow == i) {
subField.paintCursor(g, context.getCursorColor(), cursorLoc);
}
} }
// translate for next row of text
startY += subFieldHeight;
g.translate(0, subFieldHeight); g.translate(0, subFieldHeight);
translatedY += subFieldHeight; translatedY += subFieldHeight;
columns += clippingField.getText().length() + lineDelimiter.length(); columns += subField.getText().length() + lineDelimiter.length();
} }
// restore the graphics to where it was when we started.
g.translate(0, -translatedY); g.translate(0, -translatedY);
} }