Skip to content

Commit 4215082

Browse files
author
Federico Fissore
committed
Removing highlight when autoformatting. Fixes #3988.
Current highlighting logic is a bit buggy: see bobbylight/RSyntaxTextArea#150.
1 parent cc1ed44 commit 4215082

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

app/src/cc/arduino/packages/formatter/AStyle.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ public void run() {
9191
int line = getLineOfOffset(textArea);
9292
int lineOffset = getLineOffset(textArea, line);
9393

94-
editor.getTextArea().getUndoManager().beginInternalAtomicEdit();
94+
textArea.getUndoManager().beginInternalAtomicEdit();
95+
editor.removeAllLineHighlights();
9596
editor.setText(formattedText);
9697
editor.getSketch().setModified(true);
97-
editor.getTextArea().getUndoManager().endInternalAtomicEdit();
98+
textArea.getUndoManager().endInternalAtomicEdit();
9899

99100
if (line != -1 && lineOffset != -1) {
100101
try {

app/src/processing/app/Editor.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import processing.app.helpers.OSUtils;
4242
import processing.app.helpers.PreferencesMapException;
4343
import processing.app.legacy.PApplet;
44-
import processing.app.syntax.PdeKeywords;
4544
import processing.app.syntax.ArduinoTokenMakerFactory;
45+
import processing.app.syntax.PdeKeywords;
4646
import processing.app.syntax.SketchTextArea;
4747
import processing.app.tools.DiscourseFormat;
4848
import processing.app.tools.MenuScroller;
@@ -2006,7 +2006,7 @@ public BuildHandler(boolean verbose, boolean saveHex) {
20062006
@Override
20072007
public void run() {
20082008
try {
2009-
textarea.removeAllLineHighlights();
2009+
removeAllLineHighlights();
20102010
sketch.prepare();
20112011
sketch.build(verbose, saveHex);
20122012
statusNotice(tr("Done compiling."));
@@ -2024,6 +2024,15 @@ public void run() {
20242024
}
20252025
}
20262026

2027+
public void removeAllLineHighlights() {
2028+
textarea.removeAllLineHighlights();
2029+
}
2030+
2031+
public void addLineHighlight(int line) throws BadLocationException {
2032+
textarea.addLineHighlight(line, new Color(1, 0, 0, 0.2f));
2033+
textarea.setCaretPosition(textarea.getLineStartOffset(line));
2034+
}
2035+
20272036
private class DefaultStopHandler implements Runnable {
20282037
public void run() {
20292038
// TODO
@@ -2276,7 +2285,7 @@ private void updateTitle() {
22762285
public boolean handleSave(boolean immediately) {
22772286
//stopRunner();
22782287
handleStop(); // 0136
2279-
textarea.removeAllLineHighlights();
2288+
removeAllLineHighlights();
22802289

22812290
if (untitled) {
22822291
return handleSaveAs();
@@ -2430,7 +2439,7 @@ class DefaultExportHandler implements Runnable {
24302439
public void run() {
24312440

24322441
try {
2433-
textarea.removeAllLineHighlights();
2442+
removeAllLineHighlights();
24342443
if (serialMonitor != null) {
24352444
serialMonitor.suspend();
24362445
}
@@ -2876,8 +2885,7 @@ public void statusError(Exception e) {
28762885
System.err.println(I18n.format(tr("Bad error line: {0}"), line));
28772886
} else {
28782887
try {
2879-
textarea.addLineHighlight(line, new Color(1, 0, 0, 0.2f));
2880-
textarea.setCaretPosition(textarea.getLineStartOffset(line));
2888+
addLineHighlight(line);
28812889
} catch (BadLocationException e1) {
28822890
e1.printStackTrace();
28832891
}

0 commit comments

Comments
 (0)