Skip to content

Commit 7991e6b

Browse files
Change workaround for ctrl-slash handling in RSyntaxTextArea
Previously, there was a handler on the text area that consumed most KEY_TYPED events with control pressed. This was added a long time ago to fix a problem with ctrl-slash doing both the toggle comment action and inserting a /. Further investigation shows that with RSyntaxTextArea this problem is still present, but is caused by a weird binding on the slash key that Arduino is not even using. Removing that binding is a cleaner workaround for this problem, so this commit switches to that workaround. Ideally this would be fixed in RSyntaxTextArea, see bobbylight/RSyntaxTextArea#157
1 parent 79589fb commit 7991e6b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

app/src/processing/app/EditorListener.java

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ public EditorListener(Editor editor) {
2222
private static final int CTRL_SHIFT = InputEvent.SHIFT_MASK | CTRL;
2323

2424
public void keyTyped(KeyEvent event) {
25-
char c = event.getKeyChar();
26-
27-
if ((event.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
28-
// The char is not control code when CTRL key pressed? It should be a shortcut.
29-
if (!Character.isISOControl(c)) {
30-
event.consume();
31-
}
32-
}
3325
}
3426

3527
@Override

app/src/processing/app/syntax/SketchTextArea.java

+2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
import processing.app.BaseNoGui;
4141
import processing.app.EditorListener;
4242
import processing.app.PreferencesData;
43+
import processing.app.helpers.Keys;
4344

45+
import javax.swing.KeyStroke;
4446
import javax.swing.event.EventListenerList;
4547
import javax.swing.event.HyperlinkEvent;
4648
import javax.swing.event.HyperlinkListener;

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

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.fife.ui.rtextarea.RTextArea;
66
import org.fife.ui.rtextarea.RTextAreaEditorKit;
77
import processing.app.PreferencesData;
8+
import processing.app.helpers.Keys;
89

910
import javax.swing.*;
1011
import javax.swing.text.DefaultEditorKit;
@@ -23,6 +24,15 @@ public SketchTextAreaDefaultInputMap() {
2324

2425
remove(KeyStroke.getKeyStroke(KeyEvent.VK_K, defaultModifier));
2526

27+
// Remove a troublesome binding for the / key. By default, RSyntaxTextArea
28+
// binds the / KEY_TYPED event to insert a / and optionally complete any XML
29+
// tags. However, since this also triggeres on ctrl-slash, this means that
30+
// in addition to toggling comments on ctrl-slash, it also inserts a slash.
31+
// Since we don't need the XML completion feature anyway, just unbind it
32+
// here. A future version of RSyntaxTextArea might fix this, see
33+
// https://github.com/bobbylight/RSyntaxTextArea/issues/157.
34+
remove(KeyStroke.getKeyStroke('/'));
35+
2636
if (PreferencesData.getBoolean("editor.advanced")) {
2737
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, alt), RTextAreaEditorKit.rtaLineDownAction);
2838
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, alt), RTextAreaEditorKit.rtaLineUpAction);

0 commit comments

Comments
 (0)