1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-16 22:27:59 +03:00

Formatter: cursor position is saved when invoking autoformat. Fixes #2293

This commit is contained in:
Federico Fissore
2014-09-30 17:17:13 +02:00
parent 170816181a
commit 1b783fa48c
5 changed files with 91 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package cc.arduino.packages.formatter;
import processing.app.Base;
import processing.app.Editor;
import processing.app.helpers.FileUtils;
import processing.app.syntax.JEditTextArea;
import processing.app.tools.Tool;
import java.io.File;
@@ -54,8 +55,13 @@ public class AStyle implements Tool {
return;
}
JEditTextArea textArea = editor.getTextArea();
int line = textArea.getLineOfOffset(textArea.getCaretPosition());
int lineOffset = textArea.getCaretPosition() - textArea.getLineStartOffset(line);
editor.setText(formattedText);
editor.getSketch().setModified(true);
textArea.setCaretPosition(Math.min(textArea.getLineStartOffset(line) + lineOffset, textArea.getSafeLineStopOffset(line) - 1));
// mark as finished
editor.statusNotice(_("Auto Format finished."));
}