mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
New editor: ALT+ BACKSPACE deletes next word (OSX only). See #3098
This commit is contained in:
@ -35,8 +35,8 @@ import org.fife.ui.rsyntaxtextarea.Theme;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
import org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip;
|
||||
import org.fife.ui.rtextarea.RTextArea;
|
||||
import org.fife.ui.rtextarea.RTextAreaUI;
|
||||
import org.fife.ui.rtextarea.RUndoManager;
|
||||
|
||||
import processing.app.*;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -47,7 +47,6 @@ import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.Segment;
|
||||
import javax.swing.undo.UndoManager;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
@ -478,4 +477,8 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RTextAreaUI createRTextAreaUI() {
|
||||
return new SketchTextAreaUI(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaDefaultInputMap;
|
||||
import org.fife.ui.rtextarea.RTextArea;
|
||||
import org.fife.ui.rtextarea.RTextAreaEditorKit;
|
||||
import processing.app.PreferencesData;
|
||||
|
||||
@ -23,5 +24,10 @@ public class SketchTextAreaDefaultInputMap extends RSyntaxTextAreaDefaultInputMa
|
||||
remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, alt));
|
||||
remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, alt));
|
||||
}
|
||||
|
||||
boolean isOSX = RTextArea.isOSX();
|
||||
if (isOSX) {
|
||||
put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, alt), SketchTextAreaEditorKit.rtaDeleteNextWordAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
app/src/processing/app/syntax/SketchTextAreaEditorKit.java
Normal file
65
app/src/processing/app/syntax/SketchTextAreaEditorKit.java
Normal file
@ -0,0 +1,65 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
|
||||
import org.fife.ui.rtextarea.RTextArea;
|
||||
import org.fife.ui.rtextarea.RecordableTextAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.TextAction;
|
||||
import javax.swing.text.Utilities;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit {
|
||||
|
||||
public static final String rtaDeleteNextWordAction = "RTA.DeleteNextWordAction";
|
||||
|
||||
private static final Action[] defaultActions = {
|
||||
new DeleteNextWordAction()
|
||||
};
|
||||
|
||||
@Override
|
||||
public Action[] getActions() {
|
||||
return TextAction.augmentList(super.getActions(), SketchTextAreaEditorKit.defaultActions);
|
||||
}
|
||||
|
||||
public static class DeleteNextWordAction extends RecordableTextAction {
|
||||
|
||||
public DeleteNextWordAction() {
|
||||
super(rtaDeleteNextWordAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
|
||||
if (!textArea.isEditable() || !textArea.isEnabled()) {
|
||||
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int start = textArea.getSelectionStart();
|
||||
int end = getNextWordStart(textArea, start);
|
||||
if (end > start) {
|
||||
textArea.getDocument().remove(start, end - start);
|
||||
}
|
||||
} catch (BadLocationException ex) {
|
||||
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMacroID() {
|
||||
return rtaDeleteNextWordAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the starting offset to delete. Exists so subclasses can
|
||||
* override.
|
||||
*/
|
||||
protected int getNextWordStart(RTextArea textArea, int end)
|
||||
throws BadLocationException {
|
||||
return Utilities.getNextWord(textArea, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
21
app/src/processing/app/syntax/SketchTextAreaUI.java
Normal file
21
app/src/processing/app/syntax/SketchTextAreaUI.java
Normal file
@ -0,0 +1,21 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.EditorKit;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
public class SketchTextAreaUI extends RSyntaxTextAreaUI {
|
||||
|
||||
private static final EditorKit defaultKit = new SketchTextAreaEditorKit();
|
||||
|
||||
public SketchTextAreaUI(JComponent rSyntaxTextArea) {
|
||||
super(rSyntaxTextArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditorKit getEditorKit(JTextComponent tc) {
|
||||
return defaultKit;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user