From 05be1480d48c20ee1742882c7249e353e486d1d6 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 21 Dec 2015 16:41:12 -0800 Subject: [PATCH] Fix issue #3502: behavior of Cmd+[ and Cmd+] on Mac OS X. --- .../syntax/SketchTextAreaDefaultInputMap.java | 4 +-- .../app/syntax/SketchTextAreaEditorKit.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java b/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java index f713e26d5ed..5e3b59646f1 100644 --- a/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java +++ b/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java @@ -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); diff --git a/app/src/processing/app/syntax/SketchTextAreaEditorKit.java b/app/src/processing/app/syntax/SketchTextAreaEditorKit.java index 41379ae0b0a..35574b16ca9 100644 --- a/app/src/processing/app/syntax/SketchTextAreaEditorKit.java +++ b/app/src/processing/app/syntax/SketchTextAreaEditorKit.java @@ -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() }; @@ -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. */