Skip to content
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

Don't overwrite browser zoom shortcuts #14946

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Don't overwrite browser zoom shortcuts #14946

merged 1 commit into from
Aug 3, 2023

Conversation

fjellfly
Copy link

Some browsers enable the user to set the zoomlevel of the website using Ctrl and + or -. The default version of KeyboardZoom catches these keydown events and adjusts the map zoomlevel. There might be a situation where a user wants to increase or decrease the size of e.g. the controls as well. They are not able to do this via shortcuts because they are handled by OpenLayers. To get around this, I suggest that the default KeyboardZoom should only adjust the zoom level if + or - was pressed without Ctrl being pressed at the same time. This way, the event is raised to the browser if Ctrl was pressed, too.

Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I‘d suggest fixing this directly in KeybordZoom.js, because it‘s the documented and expected behavior.

@fjellfly
Copy link
Author

I‘d suggest fixing this directly in KeybordZoom.js, because it‘s the documented and expected behavior.

True - I adjusted the code according to your suggestion.

@github-actions
Copy link

📦 Preview the website for this branch here: https://deploy-preview-14946--ol-site.netlify.app/.

@fjellfly fjellfly marked this pull request as ready for review July 26, 2023 13:40
@mike-000
Copy link
Contributor

Many keyboard layouts use the shift key to access +. Using noModifierKeys alone will prevent that working. It will need a custom function such as

 function (mapBrowserEvent) {
      return (
        (noModifierKeys(mapBrowserEvent) || shiftKeyOnly(mapBrowserEvent)) && targetNotEditable(mapBrowserEvent)
      );
 }

@fjellfly
Copy link
Author

Many keyboard layouts use the shift key to access +.

That's a good point! I extended the filter criteria to allow shift. I did this using a custom function as you suggested. I had the feeling that it could also be an option to add another ol/events/condition like noPlatformModifierKey. However, as this is my first PR to the project I wasn't sure if you prefer not to have such an additional Condition if it's only used at a single location in the code.

Comment on lines 51 to 53
: function (mapBrowserEvent) {
return (
(noModifierKeys(mapBrowserEvent) ||
shiftKeyOnly(mapBrowserEvent)) &&
targetNotEditable(mapBrowserEvent)
);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply

Suggested change
: function (mapBrowserEvent) {
return (
(noModifierKeys(mapBrowserEvent) ||
shiftKeyOnly(mapBrowserEvent)) &&
targetNotEditable(mapBrowserEvent)
);
};
: (mapBrowserEvent) => !platformModifierKeyOnly(mapBrowserEvent) && targetNotEditable(mapBrowserEvent)

?

Copy link
Contributor

@mike-000 mike-000 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On keyboards which need shift to type + browser zoom needs ctrl shift.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(although on Windows Chrome with UK keyboard ctrl = will also activate browser zoom).

@ahocevar
Copy link
Member

ahocevar commented Aug 2, 2023

@fjellfly I think having a platformModifierKey condition would make sense, which returns true when the Ctrl (or Command on Mac) modifier key is pressed.

@fjellfly
Copy link
Author

fjellfly commented Aug 3, 2023

@fjellfly I think having a platformModifierKey condition would make sense, which returns true when the Ctrl (or Command on Mac) modifier key is pressed.

@ahocevar Okay, I added a platformModifierKey condition that is used to prevent zoom if ctrl/meta is pressed.

Some browsers enable the user to set the zoomlevel of the website using `ctrl`
and `+` or `-`. The default version of `KeyboardZoom` catches these keydown
events and adjusts the map zoomlevel.
There might be a situation where a user wants to increase or decrease the size
of e.g. the controls as well. They are not able to do this via shortcuts
because they are handled by OpenLayers. To get around this the default
`KeyboardZoom` should only adjust the zoom level if `+` or `-` was pressed
without `ctrl` being pressed at the same time.  This way, the event is
raised to the browser if `ctrl` was pressed, too.
Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @fjellfly, for this excellent first-time contribution.

@ahocevar ahocevar merged commit 0cbf965 into openlayers:main Aug 3, 2023
@ahocevar
Copy link
Member

ahocevar commented Aug 4, 2023

@fjellfly There is a minor issue with the new test: on a Mac, it will fail. Instead of testing with the Ctrl key hard coded, the Ctrl or Cmd key should be used, depending on the platform. Would be great if you could create a small follow-up pull request to fix that.

@fjellfly
Copy link
Author

fjellfly commented Aug 4, 2023

@fjellfly There is a minor issue with the new test: on a Mac, it will fail. Instead of testing with the Ctrl key hard coded, the Ctrl or Cmd key should be used, depending on the platform. Would be great if you could create a small follow-up pull request to fix that.

@ahocevar Oh, of course, here is a fix for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants