Skip to content

Comments

Add keybindings for zoom in, zoom out and zoom reset#1629

Merged
glennsl merged 2 commits intoonivim:masterfrom
artsem-teal:feature/workspace/zoom-keybindings
Apr 19, 2020
Merged

Add keybindings for zoom in, zoom out and zoom reset#1629
glennsl merged 2 commits intoonivim:masterfrom
artsem-teal:feature/workspace/zoom-keybindings

Conversation

@artsem-teal
Copy link
Contributor

Added keybindings for zoom in, zoom out and zoom reset according #1423 issue.

I checked zooming behavior in VSCode and they have next logic: default value is 0, minimum is -8 and maximum is 9. Zooming step is 1 which equals to 20%.

Short summary what was done in this PR:

  1. Removed minimum value of 1.0 for zooming in ConfigurationStoreConnector;
  2. Added keybindings to KeyBindingsStoreConnector for Cmd + =, Ctrl + =, Cmd + -, Ctrl + -, Cmd + 0 and Ctrl + 0;
  3. Added Commands and zoom effect handler to VimStoreConnector.

Minimum value for zooming is 0 because on lower values there is no changes in UI.

And probably there should be some logic to process Cmd + = on Mac and Ctrl + = on Linux/Windows for example. Because with current implementation both of those combinations are working on Mac.

Would love to hear any comments and suggestion!

@CLAassistant
Copy link

CLAassistant commented Apr 18, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@glennsl glennsl left a comment

Choose a reason for hiding this comment

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

Awesome @ArtemDrozdov. I haven't tried it out yet, just looked over the code, but it seems sound to me! I have a few suggestions and a reorganization request below though.

Comment on lines 983 to 986
let zoomStep = 0.2;
let defaultZoom = 1.0;
let minZoomValue = 0.0;
let maxZoomValue = 2.8;
Copy link
Member

Choose a reason for hiding this comment

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

Could you put these in a Constants sub-module at the top of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course.

Comment on lines 993 to 998
let calculatedZoomValue =
switch (zoomAction) {
| ZoomIn => currentZoomValue +. zoomStep
| ZoomOut => currentZoomValue -. zoomStep
| ZoomReset => defaultZoom
};
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason you pass in a zoomAction instead of just passing in the value directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by

instead of just passing in the value directly

Can't get your point.

Copy link
Member

Choose a reason for hiding this comment

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

Looking closer, I guess you can't pass in currentZoomValue +. zoomStep) directly instead of ZoomIn because you need currentZoomValue. But you could do zoomEffect(state, zoom => zoom +. zoomStep).

Comment on lines 1000 to 1004
let newZoomValue =
calculatedZoomValue < minZoomValue
? minZoomValue
: calculatedZoomValue > maxZoomValue
? maxZoomValue : calculatedZoomValue;
Copy link
Member

Choose a reason for hiding this comment

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

You can use Utility.IntEx.clamp for this. It would be significantly more readable I think.

Comment on lines 1076 to 1087
| Command("workbench.action.zoomIn") => (
state,
zoomEffect(state, ZoomIn),
)
| Command("workbench.action.zoomOut") => (
state,
zoomEffect(state, ZoomOut),
)
| Command("workbench.action.zoomReset") => (
state,
zoomEffect(state, ZoomReset),
)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason for these and the effect to need to live in VimStoreConnector. Could you move it to CommandStoreConnector instead (unless there's a reason I don't see)?

@artsem-teal
Copy link
Contributor Author

Pushed changes according @glennsl comments:

  1. Moved effect logic from VimStoreConnector to CommandStoreConnector;
  2. Added Constants submodule in CommandStoreConnector;
  3. Changed effect logic a little bit.

Copy link
Member

@glennsl glennsl left a comment

Choose a reason for hiding this comment

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

Looks and works great. Thanks @ArtemDrozdov!

@glennsl
Copy link
Member

glennsl commented Apr 19, 2020

Oh, CI fails on an unused variable warning. That should be a quick fix though.

@glennsl glennsl merged commit 5e1ca7f into onivim:master Apr 19, 2020
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