Skip to content

Commit 05be148

Browse files
committed
Fix issue #3502: behavior of Cmd+[ and Cmd+] on Mac OS X.
1 parent fa4876b commit 05be148

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

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

4646
remove(KeyStroke.getKeyStroke(KeyEvent.VK_J, defaultModifier));
4747

48-
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), DefaultEditorKit.insertTabAction);
49-
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
48+
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
49+
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), SketchTextAreaEditorKit.rtaIncreaseIndentAction);
5050

5151
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, defaultModifier | shift), DefaultEditorKit.selectionBeginAction);
5252
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
*/

0 commit comments

Comments
 (0)