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:
@@ -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."));
|
||||
}
|
||||
|
Reference in New Issue
Block a user