FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #3848 from JakubValtar/multiline-wiggly-underlines · qicny/processing@ce273f5 · GitHub

Repository navigation

Commit ce273f5

Browse files
committed
Merge pull request processing#3848 from JakubValtar/multiline-wiggly-underlines
Multiline wiggly underlines
2 parents 274d81d + 11296ea commit ce273f5

3 files changed

Lines changed: 72 additions & 61 deletions

File tree

‎java/src/processing/mode/java/JavaEditor.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,27 @@ public List<LineMarker> getErrorPoints() {
24792479
}
24802480

24812481

2482+
/**
2483+
* @return the LineMarker for the first error or warning on 'line'
2484+
*/
2485+
public LineMarker findError(int line) {
2486+
List<LineMarker> errorPoints = getErrorPoints();
2487+
JavaTextArea textArea = getJavaTextArea();
2488+
synchronized (errorPoints) {
2489+
for (LineMarker emarker : errorPoints) {
2490+
Problem p = emarker.getProblem();
2491+
int pStartLine = p.getLineNumber();
2492+
int pEndOffset = textArea.getLineStartOffset(pStartLine) + p.getPDELineStopOffset() + 1;
2493+
int pEndLine = textArea.getLineOfOffset(pEndOffset);
2494+
if (line >= pStartLine && line <= pEndLine) {
2495+
return emarker;
2496+
}
2497+
}
2498+
}
2499+
return null;
2500+
}
2501+
2502+
24822503
/*
24832504
public void clearErrorPoints() {
24842505
List<LineMarker> errorPoints = getErrorPoints();

‎java/src/processing/mode/java/pdex/ErrorCheckerService.java‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,20 +1064,16 @@ private void updateEditorStatus() {
10641064
// editor.statusNotice("Position: " +
10651065
// editor.getTextArea().getCaretLine());
10661066
if (JavaMode.errorCheckEnabled) {
1067-
List<LineMarker> errorPoints = editor.getErrorPoints();
1068-
synchronized (errorPoints) {
1069-
for (LineMarker emarker : errorPoints) {
1070-
if (emarker.getProblem().getLineNumber() == editor.getTextArea().getCaretLine()) {
1071-
if (emarker.getType() == LineMarker.WARNING) {
1072-
editor.statusMessage(emarker.getProblem().getMessage(),
1073-
JavaEditor.STATUS_INFO);
1074-
} else {
1075-
editor.statusMessage(emarker.getProblem().getMessage(),
1076-
JavaEditor.STATUS_COMPILER_ERR);
1077-
}
1078-
return;
1079-
}
1067+
LineMarker errorMarker = editor.findError(editor.getTextArea().getCaretLine());
1068+
if (errorMarker != null) {
1069+
if (errorMarker.getType() == LineMarker.WARNING) {
1070+
editor.statusMessage(errorMarker.getProblem().getMessage(),
1071+
JavaEditor.STATUS_INFO);
1072+
} else {
1073+
editor.statusMessage(errorMarker.getProblem().getMessage(),
1074+
JavaEditor.STATUS_COMPILER_ERR);
10801075
}
1076+
return;
10811077
}
10821078
}
10831079

‎java/src/processing/mode/java/pdex/JavaTextAreaPainter.java‎

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,8 @@ public class JavaTextAreaPainter extends TextAreaPainter
7474
protected Color gutterTextColor;
7575
protected Color gutterLineHighlightColor;
7676

77-
public static class ErrorLineCoord {
78-
public int xStart;
79-
public int xEnd;
80-
public int yStart;
81-
public int yEnd;
82-
public Problem problem;
83-
84-
public ErrorLineCoord(int xStart, int xEnd, int yStart, int yEnd, Problem problem) {
85-
this.xStart = xStart;
86-
this.xEnd = xEnd;
87-
this.yStart = yStart;
88-
this.yEnd = yEnd;
89-
this.problem = problem;
90-
}
91-
}
92-
public List<ErrorLineCoord> errorLineCoords = new ArrayList<>();
9377

94-
95-
public JavaTextAreaPainter(JavaTextArea textArea, TextAreaDefaults defaults) {
78+
public JavaTextAreaPainter(final JavaTextArea textArea, TextAreaDefaults defaults) {
9679
super(textArea, defaults);
9780

9881
addMouseListener(new MouseAdapter() {
@@ -134,11 +117,28 @@ public void mousePressed(MouseEvent event) {
134117
addMouseMotionListener(new MouseMotionAdapter() {
135118
@Override
136119
public void mouseMoved(final MouseEvent evt) {
137-
for (ErrorLineCoord coord : errorLineCoords) {
138-
if (evt.getX() >= coord.xStart && evt.getX() <= coord.xEnd &&
139-
evt.getY() >= coord.yStart && evt.getY() <= coord.yEnd + 2) {
140-
setToolTipText(coord.problem.getMessage());
141-
break;
120+
int line = textArea.yToLine(evt.getY());
121+
int x = evt.getX();
122+
123+
LineMarker marker = getJavaEditor().findError(line);
124+
if (marker != null) {
125+
Problem problem = marker.getProblem();
126+
127+
int lineOffset = textArea.getLineStartOffset(problem.getLineNumber());
128+
129+
int lineStart = textArea.getLineStartOffset(line);
130+
int lineEnd = textArea.getLineStopOffset(line);
131+
132+
int errorStart = lineOffset + problem.getPDELineStartOffset();
133+
int errorEnd = lineOffset + problem.getPDELineStopOffset() + 1;
134+
135+
int startOffset = Math.max(errorStart, lineStart) - lineStart;
136+
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;
137+
138+
if (x >= getTextArea().offsetToX(line, startOffset) &&
139+
x <= getTextArea().offsetToX(line, stopOffset)) {
140+
setToolTipText(problem.getMessage());
141+
evt.consume();
142142
}
143143
}
144144
}
@@ -337,22 +337,6 @@ static private String trimRight(String str) {
337337
}
338338

339339

340-
/**
341-
* @return the LineMarker for the first error or warning on 'line'
342-
*/
343-
private LineMarker findError(int line) {
344-
List<LineMarker> errorPoints = getJavaEditor().getErrorPoints();
345-
synchronized (errorPoints) {
346-
for (LineMarker emarker : errorPoints) {
347-
if (emarker.getProblem().getLineNumber() == line) {
348-
return emarker;
349-
}
350-
}
351-
}
352-
return null;
353-
}
354-
355-
356340
/**
357341
* Paints the underline for an error/warning line
358342
*
@@ -369,22 +353,29 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
369353
return;
370354
}
371355

372-
errorLineCoords.clear();
373-
LineMarker marker = findError(line);
356+
LineMarker marker = getJavaEditor().findError(line);
374357
if (marker != null) {
375358
Problem problem = marker.getProblem();
376359

360+
int offset = textArea.getLineStartOffset(problem.getLineNumber());
361+
362+
int startOffset = offset + problem.getPDELineStartOffset();
363+
int stopOffset = offset + problem.getPDELineStopOffset() + 1;
364+
365+
int lineOffset = textArea.getLineStartOffset(line);
366+
367+
int wiggleStart = Math.max(startOffset, lineOffset);
368+
int wiggleStop = Math.min(stopOffset, textArea.getLineStopOffset(line));
369+
377370
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
378-
int start = textArea.getLineStartOffset(line) + problem.getPDELineStartOffset();
379-
int length = 1 + problem.getPDELineStopOffset() - problem.getPDELineStartOffset();
380371

381372
try {
382373
String badCode = null;
383374
String goodCode = null;
384375
try {
385376
SyntaxDocument doc = textArea.getDocument();
386-
badCode = doc.getText(start, length);
387-
goodCode = doc.getText(textArea.getLineStartOffset(line), problem.getPDELineStartOffset());
377+
badCode = doc.getText(wiggleStart, wiggleStop - wiggleStart);
378+
goodCode = doc.getText(lineOffset, wiggleStart - lineOffset);
388379
//log("paintErrorLine() LineText GC: " + goodCode);
389380
//log("paintErrorLine() LineText BC: " + badCode);
390381
} catch (BadLocationException bl) {
@@ -402,12 +393,14 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
402393
int rw = fm.stringWidth(badCode.trim()); // real width
403394
int x1 = fm.stringWidth(goodCode) + (aw - rw);
404395
int y1 = y + fm.getHeight() - 2, x2 = x1 + rw;
396+
397+
if (line != problem.getLineNumber()) {
398+
x1 = 0; // on the following lines, wiggle extends to the left border
399+
}
405400
// Adding offsets for the gutter
406401
x1 += Editor.LEFT_GUTTER;
407402
x2 += Editor.LEFT_GUTTER;
408403

409-
errorLineCoords.add(new ErrorLineCoord(x1, x2, y, y1, problem));
410-
411404
gfx.setColor(errorUnderlineColor);
412405
if (marker.getType() == LineMarker.WARNING) {
413406
gfx.setColor(warningUnderlineColor);
@@ -480,7 +473,8 @@ public String getToolTipText(MouseEvent event) {
480473
return super.getToolTipText(event);
481474
}
482475
if (!(Character.isLetterOrDigit(s.charAt(x)) ||
483-
s.charAt(x) == '_' || s.charAt(x) == '$')) {
476+
s.charAt(x) == '_' || s.charAt(x) == '$' || s.charAt(x) == '{' ||
477+
s.charAt(x) == '}')) {
484478
setToolTipText(null);
485479
return super.getToolTipText(event);
486480
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL