-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Zoom-in/out using keyboard shortcut not working correctly (#424) #589
base: master
Are you sure you want to change the base?
Conversation
…ller can handle a 2nd set of accelerators.
Unfortunately key code assignment seems to be broken as it does not match with given system locale.
Testing on Mac OS 13.2.1 Preview appboth CMD + = and CMD + SHIFT + = zooms in SceneBuilder appCMD + = does nothing. |
I will review this and complement the table above with our findings. Actually I've tested the above table on an older x86 Macbook with MacOS 10.12. |
zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N | ||
zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N | ||
// Neither KeyCode.MINUS or KeyCode.SUBTRACT seem to work on macOS. | ||
// No chance to test on keyboard with num key pad yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a strange behavior 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reproduce this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can reproduce this on mac.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be this requires a different approach depending on the keyboard type. Are you using a separate keyboard or numpad? I've just an old laptop available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update 2024 and JavaFX 23.0.1,
zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.PLUS, modifier));
zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, modifier));
works just fine on macOS
@Oliver-Loeffler If you need any help, feel free to ping me. It would be nice to have this PR merged before we merge #619 and release SB 20. |
I will look into this one tonight.
|
Well I just learned that Zooming was also a thing for the Preview. Never thought about this one, just worked on the Zoom function for the editor window. Indeed, I'll update this accordingly. I have tested the key strokes as described in the table above. Testing on Mac OS 12.0.1
This behavior was actually the reason why I've implemented I'll take an image of my keyboard - may be this will help to figure out whats off. Unfortunately I have no numpad for my Mac, so I cannot test this. |
if (EditorPlatform.IS_MAC && "+".equals(event.getText())) { | ||
runActionController(zoomInController, event); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also now special handling of CMD
++
for MacOS in the MenuBar controller. Could you please try this @abhinayagarwal ?
c953e1f
to
fdec9b9
Compare
Well, the preview window zoom seems to be a different thing, actually I would take care for this in a different PR. I've got this somehow working but not sure if this is desired. We can couple the preview zoom to the workspace zoom or we can design it a way that preview and workspace can operate with independent zoom levels. Key code / menmoic assignments can stay the same, which part of the program than receives the zoom instruction is the decided by window selection. |
I will not get this one completed before end of next week. As I started digging into this topic I found, that the proposed key combinations using Eventually its even thinkable to make those key combinations configurable. As of now, I have not yet found how to detect which keyboard layout is effectively used for a system. If this would be detectable, one could generate key combinations for certain layouts and a generic combination which fits all. On the other hand, it seems that zoom is actually not yet implemented for the preview window. If this works in some cases, then by accident. This should be solved by a separate PR. What do you think about this @abhinayagarwal ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on macOS, and it looks good. I've left a few comments.
* | ||
* @param event {@link KeyEvent} If any action is triggered, the event will be consumed. | ||
*/ | ||
public void handleAdditionalZoomAccelerators(KeyEvent event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleAdditionalZoomAccelerators
is public API, so it should check if the modifier is down (any future use of this API else where will fail otherwise if there is no check):
public void handleAdditionalZoomAccelerators(KeyEvent event) {
if (event == null || !(EditorPlatform.IS_MAC ? event.isMetaDown() : event.isControlDown())) {
return;
}
...
}
``
zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); // NOI18N | ||
zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); // NOI18N | ||
// Neither KeyCode.MINUS or KeyCode.SUBTRACT seem to work on macOS. | ||
// No chance to test on keyboard with num key pad yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update 2024 and JavaFX 23.0.1,
zoomInMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.PLUS, modifier));
zoomOutMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, modifier));
works just fine on macOS
zoomMenu.getItems().add(zoomOutMenuItem); | ||
|
||
if (EditorPlatform.IS_MAC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unneeded if-else, new KeyCodeCombination(KeyCode.PLUS, modifier)
and new KeyCodeCombination(KeyCode.MINUS, modifier)
work fine on macOS with JavaFX 23.0.1
return; | ||
} | ||
|
||
if (EditorPlatform.IS_MAC && "+".equals(event.getText())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyCode.PLUS == event.getCode()
works fine
public void handleAdditionalZoomAccelerators(KeyEvent event) { | ||
// For unknown reasons, on macOS 12.0.1 with Java 17/JavaFX 19 the "-" key code | ||
// is not properly accepted hence this handling here. | ||
if (EditorPlatform.IS_MAC && "-".equals(event.getText())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyCode.MINUS == event.getCode()
works fine
Zoom-In/Out was supposed to work with keyboard shortcuts.
For Zoom-In
MODIFIER
++
and for Zoom-OutMODIFIER
+/
were defined.The predefined KeyCombinations were not working, there seems something wrong with how KeyCodes are handled especially on macOS but also on Windows. This might become an issue for OpenJFX which is a separate thing.
I've played a while with suitable settings which work on Win/Mac/Linux and settled with following idea:
CTRL
++
CTRL
+-
CTRL
++
(on num key pad)CTRL
+-
(on num key pad)CMD
++
CMD
+-
CMD
++
(on num key pad)CMD
+-
(on num key pad)SHIFT
+CTRL
+up
SHIFT
+CTRL
+right
SHIFT
+CTRL
+left
SHIFT
+CTRL
+down
SHIFT
+CMD
+up
SHIFT
+CMD
+right
SHIFT
+CMD
+left
SHIFT
+CMD
+down
The
DocumentWindowController
offers amainKeyEventFilter
where those double accelerators can be tracked.All key handling happens in
MenuBarController
but this is called frommainKeyEventFilter
inDocumentWindowController
.Issue
Fixes #424
Progress