File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
app/src/cc/arduino/packages/formatter Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -99,19 +99,25 @@ public void run() {
9999 editor .getTextArea ().getUndoManager ().endInternalAtomicEdit ();
100100
101101 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+ }
103107 }
104108
105109 // mark as finished
106110 editor .statusNotice (_ ("Auto Format finished." ));
107111 }
108112
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 ;
114119 }
120+ textArea .setCaretPosition (caretPosition );
115121 }
116122
117123 private int getLineOffset (SketchTextArea textArea , int line ) {
You can’t perform that action at this time.
0 commit comments