Skip to content

Commit ab31897

Browse files
committed
Fixed keyboard shortcut issue on all platforms, re-implemented manual shortcut registration. Added alternative shortcut handling for Move Lines functionality.
1 parent bb80a78 commit ab31897

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

app/src/processing/app/ui/Editor.java

+23-8
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,29 @@ public void windowGainedFocus(WindowEvent e) {
349349

350350
// Enable window resizing (which allows for full screen button)
351351
setResizable(true);
352+
353+
{
354+
// Move Lines Keyboard Shortcut (Alt + Arrow Up/Down)
355+
KeyStroke moveUpKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK);
356+
final String MOVE_UP_ACTION_KEY = "moveLinesUp";
357+
textarea.getInputMap(JComponent.WHEN_FOCUSED).put(moveUpKeyStroke, MOVE_UP_ACTION_KEY);
358+
textarea.getActionMap().put(MOVE_UP_ACTION_KEY, new AbstractAction() {
359+
@Override
360+
public void actionPerformed(ActionEvent e) {
361+
handleMoveLines(true);
362+
}
363+
});
364+
365+
KeyStroke moveDownKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK);
366+
final String MOVE_DOWN_ACTION_KEY = "moveLinesDown";
367+
textarea.getInputMap(JComponent.WHEN_FOCUSED).put(moveDownKeyStroke, MOVE_DOWN_ACTION_KEY);
368+
textarea.getActionMap().put(MOVE_DOWN_ACTION_KEY, new AbstractAction() {
369+
@Override
370+
public void actionPerformed(ActionEvent e) {
371+
handleMoveLines(false);
372+
}
373+
});
374+
}
352375
}
353376

354377

@@ -821,14 +844,6 @@ protected JMenu buildEditMenu() {
821844
editMenuUpdatable.add(action);
822845
menu.add(item);
823846

824-
item = new JMenuItem("Move Selected Lines Up");
825-
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK));
826-
item.addActionListener(e -> handleMoveLines(true));
827-
828-
item = new JMenuItem("Move Selected Lines Down");
829-
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK));
830-
item.addActionListener(e -> handleMoveLines(false));
831-
832847

833848
// Update copy/cut state on selection/de-selection
834849
menu.addMenuListener(new MenuListener() {

0 commit comments

Comments
 (0)