Skip to content

Commit

Permalink
Fix issue arduino#3502: behavior of Cmd+[ and Cmd+] on Mac OS X.
Browse files Browse the repository at this point in the history
  • Loading branch information
damellis committed Dec 22, 2015
1 parent fa4876b commit 05be148
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public SketchTextAreaDefaultInputMap() {

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

put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), DefaultEditorKit.insertTabAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, defaultModifier), RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, defaultModifier), SketchTextAreaEditorKit.rtaIncreaseIndentAction);

put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, defaultModifier | shift), DefaultEditorKit.selectionBeginAction);
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, defaultModifier | shift), DefaultEditorKit.selectionEndAction);
Expand Down
35 changes: 35 additions & 0 deletions app/src/processing/app/syntax/SketchTextAreaEditorKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit {

public static final String rtaDeleteNextWordAction = "RTA.DeleteNextWordAction";
public static final String rtaDeleteLineToCursorAction = "RTA.DeleteLineToCursorAction";
public static final String rtaIncreaseIndentAction = "RTA.IncreaseIndentAction";

private static final Action[] defaultActions = {
new DeleteNextWordAction(),
new DeleteLineToCursorAction(),
new IncreaseIndentAction(),
new SelectWholeLineAction(),
new ToggleCommentAction()
};
Expand Down Expand Up @@ -103,6 +105,39 @@ public String getMacroID() {

}

/**
* Increases the indent of the selected or current line(s).
*/
public static class IncreaseIndentAction extends RSyntaxTextAreaEditorKit.InsertTabAction {

public IncreaseIndentAction() {
super(rtaIncreaseIndentAction);
}

@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
int caretPosition = textArea.getCaretPosition();
boolean noSelec = textArea.getSelectedText() == null;

// if no selection, focus on first char.
if (noSelec) {
try {
int line = textArea.getCaretLineNumber();
int startOffset = textArea.getLineStartOffset(line);
textArea.setCaretPosition(startOffset);
} catch (BadLocationException ex) {
}
}

// Insert Tab or Spaces..
super.actionPerformedImpl(e, textArea);

if (noSelec) {
textArea.setCaretPosition(caretPosition + (textArea.getTabsEmulated() ? textArea.getTabSize() : 1));
}
}
}

/**
* Selects the line around the caret.
*/
Expand Down

0 comments on commit 05be148

Please sign in to comment.