Skip to content

Commit

Permalink
Add keybindings for zoom in, zoom out and zoom reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Drozdov committed Apr 18, 2020
1 parent 10f3137 commit 94321c4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
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
53 changes: 53 additions & 0 deletions src/Store/VimStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type commandLineCompletionMeet = {
position: int,
};

type zoomAction =
| ZoomIn
| ZoomOut
| ZoomReset;

let getCommandLineCompletionsMeet = (str: string, position: int) => {
let len = String.length(str);

Expand Down Expand Up @@ -975,6 +980,42 @@ let start =
});
};

let zoomStep = 0.2;
let defaultZoom = 1.0;
let minZoomValue = 0.0;
let maxZoomValue = 2.8;
let zoomEffect = (state: State.t, zoomAction) =>
Isolinear.Effect.create(~name="vim.zoom", () => {
let configuration = state.configuration;
let currentZoomValue =
Core.Configuration.getValue(c => c.uiZoom, configuration);

let calculatedZoomValue =
switch (zoomAction) {
| ZoomIn => currentZoomValue +. zoomStep
| ZoomOut => currentZoomValue -. zoomStep
| ZoomReset => defaultZoom
};

let newZoomValue =
calculatedZoomValue < minZoomValue
? minZoomValue
: calculatedZoomValue > maxZoomValue
? maxZoomValue : calculatedZoomValue;

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

let updater = (state: State.t, action: Actions.t) => {
switch (action) {
| ConfigurationSet(configuration) => (
Expand Down Expand Up @@ -1032,6 +1073,18 @@ let start =
state,
synchronizeEditorEffect(state),
)
| Command("workbench.action.zoomIn") => (
state,
zoomEffect(state, ZoomIn),
)
| Command("workbench.action.zoomOut") => (
state,
zoomEffect(state, ZoomOut),
)
| Command("workbench.action.zoomReset") => (
state,
zoomEffect(state, ZoomReset),
)
| Command("terminal.normalMode") =>
let maybeBufferId =
state
Expand Down

0 comments on commit 94321c4

Please sign in to comment.