Skip to content

Commit d3e0693

Browse files
committed
handle fall-through cases for plain text file editing (fixes #5628)
1 parent 3436051 commit d3e0693

3 files changed

Lines changed: 29 additions & 36 deletions

File tree

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ public int lineToY(int line) {
594594
public int yToLine(int y) {
595595
FontMetrics fm = painter.getFontMetrics();
596596
int height = fm.getHeight();
597-
return Math.max(0,Math.min(getLineCount() - 1,
598-
y / height + firstLine));
597+
return Math.max(0, Math.min(getLineCount() - 1, y / height + firstLine));
599598
}
600599

601600

@@ -1033,8 +1032,10 @@ public final void getText(int start, int len, Segment segment) {
10331032
try {
10341033
document.getText(start,len,segment);
10351034

1036-
} catch(BadLocationException bl) {
1035+
} catch (BadLocationException bl) {
10371036
bl.printStackTrace();
1037+
System.err.format("Bad Location: %d for start %d and length %d",
1038+
bl.offsetRequested(), start, len);
10381039
segment.offset = segment.count = 0;
10391040
}
10401041
}

app/src/processing/app/syntax/TextAreaPainter.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,6 @@ public Segment getCurrentLine() {
604604
}
605605

606606

607-
// /** Old paintLine() method with kooky args order, kept around for X Mode. */
608-
// @Deprecated
609-
// protected void paintLine(Graphics gfx, TokenMarker tokenMarker,
610-
// int line, int x) {
611-
// Font defaultFont = getFont();
612-
// Color defaultColor = getForeground();
613607
protected void paintLine(Graphics gfx, int line, int x,
614608
TokenMarkerState tokenMarker) {
615609
currentLineIndex = line;
@@ -625,40 +619,37 @@ protected void paintLine(Graphics gfx, int line, int x,
625619
}
626620

627621

628-
// protected void paintLine(Graphics gfx, int line, int x,
629-
// TokenMarker tokenMarker) {
630-
// paintLine(gfx, tokenMarker, line, x);
631-
// }
632-
633-
634-
// protected void paintPlainLine(Graphics gfx, int line, Font defaultFont,
635-
// Color defaultColor, int x, int y) {
636622
protected void paintPlainLine(Graphics gfx, int line, int x, int y) {
637-
paintHighlight(gfx,line,y);
638-
textArea.getLineText(line, currentLine);
623+
paintHighlight(gfx, line, y);
639624

640-
// gfx.setFont(plainFont);
641-
// gfx.setFont(defaultFont);
642-
// gfx.setColor(defaultColor);
625+
// don't try to draw lines past where they exist in the document
626+
// https://github.com/processing/processing/issues/5628
627+
if (line < textArea.getLineCount()) {
628+
textArea.getLineText(line, currentLine);
643629

644-
int x0 = x - textArea.getHorizontalOffset();
630+
int x0 = x - textArea.getHorizontalOffset();
631+
// prevent the blinking from drawing with last color used
632+
// https://github.com/processing/processing/issues/5628
633+
gfx.setColor(defaults.fgcolor);
634+
gfx.setFont(plainFont);
645635

646-
y += fm.getHeight();
647-
// doesn't respect fixed width like it should
636+
y += fm.getHeight();
637+
// doesn't respect fixed width like it should
648638
// x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0);
649639
// int w = fm.charWidth(' ');
650-
for (int i = 0; i < currentLine.count; i++) {
651-
gfx.drawChars(currentLine.array, currentLine.offset+i, 1, x, y);
652-
x = currentLine.array[currentLine.offset + i] == '\t' ?
640+
for (int i = 0; i < currentLine.count; i++) {
641+
gfx.drawChars(currentLine.array, currentLine.offset+i, 1, x, y);
642+
x = currentLine.array[currentLine.offset + i] == '\t' ?
653643
x0 + (int)nextTabStop(x - x0, i) :
654644
x + fm.charWidth(currentLine.array[currentLine.offset+i]);
655-
textArea.offsetToX(line, currentLine.offset + i);
656-
}
645+
//textArea.offsetToX(line, currentLine.offset + i);
646+
}
657647

658-
// Draw characters via input method.
659-
if (compositionTextPainter != null &&
648+
// Draw characters via input method.
649+
if (compositionTextPainter != null &&
660650
compositionTextPainter.hasComposedTextLayout()) {
661-
compositionTextPainter.draw(gfx, defaults.lineHighlightColor);
651+
compositionTextPainter.draw(gfx, defaults.lineHighlightColor);
652+
}
662653
}
663654
if (defaults.eolMarkers) {
664655
gfx.setColor(defaults.eolMarkerColor);
@@ -667,9 +658,6 @@ protected void paintPlainLine(Graphics gfx, int line, int x, int y) {
667658
}
668659

669660

670-
// protected void paintSyntaxLine(Graphics gfx, TokenMarker tokenMarker,
671-
// int line, Font defaultFont,
672-
// Color defaultColor, int x, int y) {
673661
protected void paintSyntaxLine(Graphics gfx, int line, int x, int y,
674662
TokenMarkerState tokenMarker) {
675663
textArea.getLineText(currentLineIndex, currentLine);

todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
0269 (3.5.3)
2+
X added reference for circle(), square(), push(), pop()
3+
_ has the reference.zip file been fixed?
24
X redo key command for Windows screwed up
35
X https://github.com/processing/processing/issues/5773
6+
X fix an editor problem with plain text (css, etc) files
7+
X https://github.com/processing/processing/issues/5628
48

59

610
contrib

0 commit comments

Comments
 (0)