Skip to content

Commit

Permalink
Add keybindings for zoom in, zoom out and zoom reset (#1629)
Browse files Browse the repository at this point in the history
* Add keybindings for zoom in, zoom out and zoom reset

* fix unused variable warning

Co-authored-by: Glenn Slotte <[email protected]>
  • Loading branch information
artsemtech and glennsl authored Apr 19, 2020
1 parent 20a8e20 commit 5e1ca7f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
46 changes: 46 additions & 0 deletions src/Store/CommandStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ open Oni_Model.Actions;

module KeyDisplayer = Oni_Components.KeyDisplayer;

module Constants = {
let zoomStep = 0.2;
let defaultZoomValue = 1.0;
let minZoomValue = 0.0;
let maxZoomValue = 2.8;
};

let pathSymlinkEnabled = (~addingLink) =>
(
Revery.Environment.os == Revery.Environment.Mac
Expand Down Expand Up @@ -265,6 +272,33 @@ let start = (getState, contributedCommands) => {
},
);

let zoomEffect = (state: State.t, getCalculatedZoomValue, _) =>
Isolinear.Effect.createWithDispatch(~name="window.zoom", dispatch => {
let configuration = state.configuration;
let currentZoomValue =
Configuration.getValue(c => c.uiZoom, configuration);

let calculatedZoomValue = getCalculatedZoomValue(currentZoomValue);
let newZoomValue =
Utility.IntEx.clamp(
calculatedZoomValue,
~hi=Constants.maxZoomValue,
~lo=Constants.minZoomValue,
);

if (newZoomValue != currentZoomValue) {
dispatch(
ConfigurationSet({
...configuration,
default: {
...configuration.default,
uiZoom: newZoomValue,
},
}),
);
};
});

let commands = [
("keyDisplayer.enable", _ => singleActionEffect(EnableKeyDisplayer)),
("keyDisplayer.disable", _ => singleActionEffect(DisableKeyDisplayer)),
Expand Down Expand Up @@ -399,6 +433,18 @@ let start = (getState, contributedCommands) => {
);
},
),
(
"workbench.action.zoomIn",
state => zoomEffect(state, zoom => zoom +. Constants.zoomStep),
),
(
"workbench.action.zoomOut",
state => zoomEffect(state, zoom => zoom -. Constants.zoomStep),
),
(
"workbench.action.zoomReset",
state => zoomEffect(state, _zoom => Constants.defaultZoomValue),
),
];

let commandMap =
Expand Down
3 changes: 1 addition & 2 deletions src/Store/ConfigurationStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ let start =
let vsync = ref(Revery.Vsync.Immediate);
let synchronizeConfigurationEffect = configuration =>
Isolinear.Effect.create(~name="configuration.synchronize", () => {
let zoomValue =
max(1.0, Configuration.getValue(c => c.uiZoom, configuration));
let zoomValue = Configuration.getValue(c => c.uiZoom, configuration);
if (zoomValue != zoom^) {
Log.infof(m => m("Setting zoom: %f", zoomValue));
setZoom(zoomValue);
Expand Down
30 changes: 30 additions & 0 deletions src/Store/KeyBindingsStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,36 @@ let start = maybeKeyBindingsFilePath => {
command: "workbench.action.previousEditor",
condition: WhenExpr.Value(True),
},
{
key: "<D-=>",
command: "workbench.action.zoomIn",
condition: WhenExpr.Value(True),
},
{
key: "<C-=>",
command: "workbench.action.zoomIn",
condition: WhenExpr.Value(True),
},
{
key: "<D-->",
command: "workbench.action.zoomOut",
condition: WhenExpr.Value(True),
},
{
key: "<C-->",
command: "workbench.action.zoomOut",
condition: WhenExpr.Value(True),
},
{
key: "<D-0>",
command: "workbench.action.zoomReset",
condition: WhenExpr.Value(True),
},
{
key: "<C-0>",
command: "workbench.action.zoomReset",
condition: WhenExpr.Value(True),
},
// TERMINAL
// Binding to open normal mode
{
Expand Down

0 comments on commit 5e1ca7f

Please sign in to comment.