Skip to content

Commit 480f2fa

Browse files
committed
Merge branch 'issue3502-indent' of https://github.com/damellis/Arduino
Fix #3502
2 parents 733a6d0 + 07903b8 commit 480f2fa

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

app/src/processing/app/Editor.java

+2-21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import processing.app.syntax.ArduinoTokenMakerFactory;
4646
import processing.app.syntax.PdeKeywords;
4747
import processing.app.syntax.SketchTextArea;
48+
import processing.app.syntax.SketchTextAreaEditorKit;
4849
import processing.app.tools.DiscourseFormat;
4950
import processing.app.tools.MenuScroller;
5051
import processing.app.tools.Tool;
@@ -1872,28 +1873,8 @@ void handleCommentUncomment() {
18721873

18731874
private void handleIndentOutdent(boolean indent) {
18741875
if (indent) {
1875-
1876-
int caretPosition = textarea.getCaretPosition();
1877-
boolean noSelec = !textarea.isSelectionActive();
1878-
1879-
// if no selection, focus on first char.
1880-
if (noSelec) {
1881-
try {
1882-
int line = textarea.getCaretLineNumber();
1883-
int startOffset = textarea.getLineStartOffset(line);
1884-
textarea.setCaretPosition(startOffset);
1885-
} catch (BadLocationException e) {
1886-
}
1887-
}
1888-
1889-
// Insert Tab or Spaces..
1890-
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.insertTabAction);
1876+
Action action = textarea.getActionMap().get(SketchTextAreaEditorKit.rtaIncreaseIndentAction);
18911877
action.actionPerformed(null);
1892-
1893-
if (noSelec) {
1894-
textarea.setCaretPosition(caretPosition);
1895-
}
1896-
18971878
} else {
18981879
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
18991880
action.actionPerformed(null);

app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public SketchTextAreaDefaultInputMap() {
5454

5555
remove(KeyStroke.getKeyStroke(KeyEvent.VK_J, defaultModifier));
5656

57-
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), DefaultEditorKit.insertTabAction);
58-
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
57+
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
58+
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), SketchTextAreaEditorKit.rtaIncreaseIndentAction);
5959

6060
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, defaultModifier | shift), DefaultEditorKit.selectionBeginAction);
6161
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, defaultModifier | shift), DefaultEditorKit.selectionEndAction);

app/src/processing/app/syntax/SketchTextAreaEditorKit.java

+35
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ public class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit {
1313

1414
public static final String rtaDeleteNextWordAction = "RTA.DeleteNextWordAction";
1515
public static final String rtaDeleteLineToCursorAction = "RTA.DeleteLineToCursorAction";
16+
public static final String rtaIncreaseIndentAction = "RTA.IncreaseIndentAction";
1617

1718
private static final Action[] defaultActions = {
1819
new DeleteNextWordAction(),
1920
new DeleteLineToCursorAction(),
21+
new IncreaseIndentAction(),
2022
new SelectWholeLineAction(),
2123
new ToggleCommentAction()
2224
};
@@ -103,6 +105,39 @@ public String getMacroID() {
103105

104106
}
105107

108+
/**
109+
* Increases the indent of the selected or current line(s).
110+
*/
111+
public static class IncreaseIndentAction extends RSyntaxTextAreaEditorKit.InsertTabAction {
112+
113+
public IncreaseIndentAction() {
114+
super(rtaIncreaseIndentAction);
115+
}
116+
117+
@Override
118+
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
119+
int caretPosition = textArea.getCaretPosition();
120+
boolean noSelec = textArea.getSelectedText() == null;
121+
122+
// if no selection, focus on first char.
123+
if (noSelec) {
124+
try {
125+
int line = textArea.getCaretLineNumber();
126+
int startOffset = textArea.getLineStartOffset(line);
127+
textArea.setCaretPosition(startOffset);
128+
} catch (BadLocationException ex) {
129+
}
130+
}
131+
132+
// Insert Tab or Spaces..
133+
super.actionPerformedImpl(e, textArea);
134+
135+
if (noSelec) {
136+
textArea.setCaretPosition(caretPosition + (textArea.getTabsEmulated() ? textArea.getTabSize() : 1));
137+
}
138+
}
139+
}
140+
106141
/**
107142
* Selects the line around the caret.
108143
*/

build/shared/revisions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARDUINO 1.6.8
33
[ide]
44
* Fixed a NullPointerException when dealing with some rare combination of package_*.json files
55
* Fixed incorrect key bindings handling for changing tab. Thanks @matthijskooijman
6+
* MacOSX: Fixed handling of add indent/remove indent shortcuts (CMD+[ and CMD+])
67

78
ARDUINO 1.6.7 - 2015.12.17
89

0 commit comments

Comments
 (0)