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

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

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
glennsl marked this conversation as resolved.
Show resolved Hide resolved
),
];

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