File tree 1 file changed +12
-6
lines changed
app/src/cc/arduino/packages/formatter
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -99,19 +99,25 @@ public void run() {
99
99
editor .getTextArea ().getUndoManager ().endInternalAtomicEdit ();
100
100
101
101
if (line != -1 && lineOffset != -1 ) {
102
- setCaretPosition (textArea , line , lineOffset );
102
+ try {
103
+ setCaretPosition (textArea , line , lineOffset );
104
+ } catch (BadLocationException e ) {
105
+ e .printStackTrace ();
106
+ }
103
107
}
104
108
105
109
// mark as finished
106
110
editor .statusNotice (_ ("Auto Format finished." ));
107
111
}
108
112
109
- private void setCaretPosition (SketchTextArea textArea , int line , int lineOffset ) {
110
- try {
111
- textArea .setCaretPosition (Math .min (textArea .getLineStartOffset (line ) + lineOffset , textArea .getLineEndOffset (line ) - 1 ));
112
- } catch (BadLocationException e ) {
113
- e .printStackTrace ();
113
+ private void setCaretPosition (SketchTextArea textArea , int line , int lineOffset ) throws BadLocationException {
114
+ int caretPosition ;
115
+ if (line < textArea .getLineCount ()) {
116
+ caretPosition = Math .min (textArea .getLineStartOffset (line ) + lineOffset , textArea .getLineEndOffset (line ) - 1 );
117
+ } else {
118
+ caretPosition = textArea .getText ().length () - 1 ;
114
119
}
120
+ textArea .setCaretPosition (caretPosition );
115
121
}
116
122
117
123
private int getLineOffset (SketchTextArea textArea , int line ) {
You can’t perform that action at this time.
0 commit comments