diff --git a/app/src/cc/arduino/packages/formatter/AStyle.java b/app/src/cc/arduino/packages/formatter/AStyle.java index 84d4b5793..a0d75d6be 100644 --- a/app/src/cc/arduino/packages/formatter/AStyle.java +++ b/app/src/cc/arduino/packages/formatter/AStyle.java @@ -91,7 +91,6 @@ public class AStyle implements Tool { int line = getLineOfOffset(textArea); int lineOffset = getLineOffset(textArea, line); - editor.removeAllLineHighlights(); editor.getCurrentTab().setText(formattedText); if (line != -1 && lineOffset != -1) { diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index 8a18b6345..6d2ce629d 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -383,6 +383,9 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage { * Replace the entire contents of this tab. */ public void setText(String what) { + // Remove all highlights, since these will all end up at the start of the + // text otherwise. Preserving them is tricky, so better just remove them. + textarea.removeAllLineHighlights(); // Set the caret update policy to NEVER_UPDATE while completely replacing // the current text. Normally, the caret tracks inserts and deletions, but // replacing the entire text will always make the caret end up at the end,