scijava / script-editor

Script Editor and Interpreter for SciJava script languages
http://imagej.net/Script_Editor
BSD 2-Clause "Simplified" License
12 stars 11 forks source link

Script editor keyboard shortcuts not working on Mac (increase/decrease font size, block comment) #20

Open GenevieveBuckley opened 6 years ago

GenevieveBuckley commented 6 years ago

There's a subset of keyboard shortcuts for the Fiji script editor that I can't get working. I'm sure this is a non-exhaustive list, but the biggest annoyances are:

I can use these shortcuts with no trouble:

System details: Mac High Sierra, 10.13.5

Fiji version: 2.0.0-rc-67/1.52d Build 1762a07c5c Date: 2018-06-04T18:22:47+0000

$ java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

ctrueden commented 6 years ago

@GenevieveBuckley I notice all the shortcuts that don't work for you are symbols rather than letters. What kind of keyboard layout do you use? Are - and + right of 0 and left of delete/backspace? Is / left of the right-side shift? Or are they somewhere else?

GenevieveBuckley commented 6 years ago

@ctrueden Yes,, the + and - keys are to the right of 0 and the left of delete, and the / key is to the left of the right side shift key:

english_notebook

This list doesn't specifically call out an 'Australian' layout, but it looks as though I have what it's calling an "English" layout (not "English - Great Britain" or "English - International").

ctrueden commented 6 years ago

Thanks @GenevieveBuckley, that layout is identical to the one on my MacBook Pro.

On my system, ⌘+ requires that shift also be pressed, since + is really just shift+=. The ⌘- shortcut works for me in all cases. The ⌘/ shortcut only works if you have a language selected from the Language menu; otherwise, it does not know which comment style to use.

With the above comments in mind, given the high level of detail on your bug report, I'm going to proceed under the assumption that your system is different and indeed none of the three shortcuts are working for you whatsoever.

I tried creating an MCVE. Here is a Java class we can use as a playground:

import java.awt.BorderLayout;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class ShortcutSandbox {
    public static void main(final String... args) { new ShortcutSandbox();  }

    private JMenu shortcuts;
    private JLabel text;

    public ShortcutSandbox() {
        final int modifierCode = InputEvent.META_DOWN_MASK;
        System.setProperty("apple.laf.useScreenMenuBar", "true");

        JFrame frame = new JFrame("Keyboard Shortcut Test");
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        JPanel pane = new JPanel();
        pane.setLayout(new BorderLayout());
        text = new JLabel("[Try some menu entries]");
        pane.add(text, BorderLayout.CENTER);
        frame.setContentPane(pane);

        JMenuBar menubar = new JMenuBar();
        frame.setJMenuBar(menubar);
        shortcuts = new JMenu("Shortcuts");
        menubar.add(shortcuts);

        createShortcut("Tee", KeyStroke.getKeyStroke(KeyEvent.VK_T, modifierCode));
        createShortcut("Zero", KeyStroke.getKeyStroke(KeyEvent.VK_0, modifierCode));
        createShortcut("Plus", KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, modifierCode));
        createShortcut("Minus", KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, modifierCode));
        createShortcut("Slash", KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, modifierCode));

        createShortcut("Shift+Equals",
            KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, modifierCode | InputEvent.SHIFT_DOWN_MASK));

        frame.pack();
        frame.setVisible(true);
    }

    private JMenuItem createShortcut(String label, KeyStroke accelerator) {
        JMenuItem item = new JMenuItem(label);
        item.setAccelerator(accelerator);
        shortcuts.add(item);
        item.addActionListener(evt -> text.setText(label));
        return item;
    }
}

It should be possible to compile and run this on the command line with:

javac ShortcutSandbox.java
java ShortcutSandbox

On my system, all keyboard shortcuts except for ⌘+ work. (If you comment out the "Shift+Equals" shortcut, then ⌘+ does still flash the menu when shift is included in the combo, but does not trigger the corresponding action.)

In the script-editor source code in TextEditor.java, the KeyStroke objects are constructed using KeyStroke.getKeyStroke(int, int) which is what the code above uses too; the "Increase font size" code uses KeyEvent.VK_PLUS, which I guess we should change to KeyEvent.VK_EQUALS with a shift modifier. And really, all of these special characters work differently on different regional layouts, which makes coding it to work on everyone's machine quite tricky.

I don't have more time to dig on this right now, but please ping back here if you uncover any further information, workarounds, thoughts, etc.

GenevieveBuckley commented 6 years ago

With the above comments in mind, given the high level of detail on your bug report, I'm going to proceed under the assumption that your system is different and indeed none of the three shortcuts are working for you whatsoever.

This is too generous :) Turns out this is true only for some shortcuts, and only for a specific set of circumstances.

The ⌘/ shortcut

⌘/ does not work for me if the language selected is:

  1. IJ1 Macro, or
  2. R

It does work well for Beanshell, Clojure, Groovy, Java, JavaScript, Ruby, and Scala.

The ⌘+ and ⌘- shortcuts

On my system, ⌘+ requires that shift also be pressed, since + is really just shift+=.

This totally fooled me - since the terminal, TextEdit, Atom, etc. also have ⌘+ listed in their menus as the shortcut for increasing text size (just like the script editor), and do not require you to press shift... I didn't even consider that.

++ does not increase font size, but +Shift++ does work. Thanks!

The ⌘- shortcut works for me in all cases.

Me too. ⌘- does decrease font size, and +Shift+- also does decrease font size. Since Shift+- technically produces an underscore it's a little odd that this works, given the explanation above about the difference between ⌘= / ⌘+. I would have expected symmetric behaviour.

ShortcutSandbox playground

From the keyboard: ⌘+ does not register any response. ⇧⌘- is not listed in the sandbox menu, but when you enter this on the keyboard it registers as 'Minus'.

⌘T registers 'Tee', as expected. ⌘0 registers 'Zero', as expected. ⌘- registers 'Minus', as expected. ⌘/ registers 'Slash', as expected. ⇧⌘+ registers 'Shift+Equals', as expected.

I don't have more time to dig on this right now, but please ping back here if you uncover any further information, workarounds, thoughts, etc.

This is completely fine, I'd say it's a fairly low priority. Font sizes are adjustable with ⌘-and ⇧⌘+, and if I happen to want a comment block in an IJ1 Macro (ie: rarely) I can toggle the language to Java briefly. I'm ok with that as a workaround.