From c95e67b0a743f617d6b4b13532548767719d54aa Mon Sep 17 00:00:00 2001 From: Artem Drozdov Date: Sat, 18 Apr 2020 19:19:23 +0300 Subject: [PATCH 1/2] Add keybindings for zoom in, zoom out and zoom reset --- src/Store/CommandStoreConnector.re | 46 ++++++++++++++++++++++++ src/Store/ConfigurationStoreConnector.re | 3 +- src/Store/KeyBindingsStoreConnector.re | 30 ++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/Store/CommandStoreConnector.re b/src/Store/CommandStoreConnector.re index 8f0643e7c6..cc998705b5 100644 --- a/src/Store/CommandStoreConnector.re +++ b/src/Store/CommandStoreConnector.re @@ -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 @@ -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)), @@ -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 = diff --git a/src/Store/ConfigurationStoreConnector.re b/src/Store/ConfigurationStoreConnector.re index a392b83525..c8ce0c3ec2 100644 --- a/src/Store/ConfigurationStoreConnector.re +++ b/src/Store/ConfigurationStoreConnector.re @@ -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); diff --git a/src/Store/KeyBindingsStoreConnector.re b/src/Store/KeyBindingsStoreConnector.re index cb2a702b6c..a7f279af41 100644 --- a/src/Store/KeyBindingsStoreConnector.re +++ b/src/Store/KeyBindingsStoreConnector.re @@ -259,6 +259,36 @@ let start = maybeKeyBindingsFilePath => { command: "workbench.action.previousEditor", condition: WhenExpr.Value(True), }, + { + key: "", + command: "workbench.action.zoomIn", + condition: WhenExpr.Value(True), + }, + { + key: "", + command: "workbench.action.zoomIn", + condition: WhenExpr.Value(True), + }, + { + key: "", + command: "workbench.action.zoomOut", + condition: WhenExpr.Value(True), + }, + { + key: "", + command: "workbench.action.zoomOut", + condition: WhenExpr.Value(True), + }, + { + key: "", + command: "workbench.action.zoomReset", + condition: WhenExpr.Value(True), + }, + { + key: "", + command: "workbench.action.zoomReset", + condition: WhenExpr.Value(True), + }, // TERMINAL // Binding to open normal mode { From be314a16708cae0dda16a8acbd0d0fb0cd7f8d71 Mon Sep 17 00:00:00 2001 From: Glenn Slotte Date: Sun, 19 Apr 2020 14:48:59 +0200 Subject: [PATCH 2/2] fix unused variable warning --- src/Store/CommandStoreConnector.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Store/CommandStoreConnector.re b/src/Store/CommandStoreConnector.re index cc998705b5..6c9cf8e629 100644 --- a/src/Store/CommandStoreConnector.re +++ b/src/Store/CommandStoreConnector.re @@ -443,7 +443,7 @@ let start = (getState, contributedCommands) => { ), ( "workbench.action.zoomReset", - state => zoomEffect(state, zoom => Constants.defaultZoomValue), + state => zoomEffect(state, _zoom => Constants.defaultZoomValue), ), ];