mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Merge branch 'issue3502-indent' of https://github.com/damellis/Arduino
Fix #3502
This commit is contained in:
commit
480f2fa0d3
@ -45,6 +45,7 @@ import processing.app.legacy.PApplet;
|
||||
import processing.app.syntax.ArduinoTokenMakerFactory;
|
||||
import processing.app.syntax.PdeKeywords;
|
||||
import processing.app.syntax.SketchTextArea;
|
||||
import processing.app.syntax.SketchTextAreaEditorKit;
|
||||
import processing.app.tools.DiscourseFormat;
|
||||
import processing.app.tools.MenuScroller;
|
||||
import processing.app.tools.Tool;
|
||||
@ -1872,28 +1873,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
private void handleIndentOutdent(boolean indent) {
|
||||
if (indent) {
|
||||
|
||||
int caretPosition = textarea.getCaretPosition();
|
||||
boolean noSelec = !textarea.isSelectionActive();
|
||||
|
||||
// if no selection, focus on first char.
|
||||
if (noSelec) {
|
||||
try {
|
||||
int line = textarea.getCaretLineNumber();
|
||||
int startOffset = textarea.getLineStartOffset(line);
|
||||
textarea.setCaretPosition(startOffset);
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Insert Tab or Spaces..
|
||||
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.insertTabAction);
|
||||
Action action = textarea.getActionMap().get(SketchTextAreaEditorKit.rtaIncreaseIndentAction);
|
||||
action.actionPerformed(null);
|
||||
|
||||
if (noSelec) {
|
||||
textarea.setCaretPosition(caretPosition);
|
||||
}
|
||||
|
||||
} else {
|
||||
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
|
||||
action.actionPerformed(null);
|
||||
|
@ -54,8 +54,8 @@ public class SketchTextAreaDefaultInputMap extends RSyntaxTextAreaDefaultInputMa
|
||||
|
||||
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);
|
||||
|
@ -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 class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@ ARDUINO 1.6.8
|
||||
[ide]
|
||||
* Fixed a NullPointerException when dealing with some rare combination of package_*.json files
|
||||
* Fixed incorrect key bindings handling for changing tab. Thanks @matthijskooijman
|
||||
* MacOSX: Fixed handling of add indent/remove indent shortcuts (CMD+[ and CMD+])
|
||||
|
||||
ARDUINO 1.6.7 - 2015.12.17
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user