diff options
author | Sandy Armstrong <sandy@xamarin.com> | 2019-03-21 19:39:46 +0300 |
---|---|---|
committer | Sandy Armstrong <sandy@xamarin.com> | 2019-04-04 17:21:12 +0300 |
commit | d6fc006f188ab814ddd9b3e60f619f4d48f14371 (patch) | |
tree | f84b022c80e441dd70514baf79a99e3bac8bbe05 /main/src/core/Mono.TextEditor.Shared | |
parent | 93f6f7ac3ee31d32793d066430bd0d183a7de8ab (diff) |
Zoom: Persist in new editor, sync with old
Zooming in either editor impacts the same configuration setting. Each
editor now listens to the setting changing, so it can update in response
to changes in the other editor.
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/824320
Diffstat (limited to 'main/src/core/Mono.TextEditor.Shared')
-rw-r--r-- | main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextEditorOptions.cs | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextEditorOptions.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextEditorOptions.cs index 2fa9fc3426..d288c97b5c 100644 --- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextEditorOptions.cs +++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextEditorOptions.cs @@ -26,8 +26,11 @@ using System; using System.Diagnostics; -using MonoDevelop.Core; + using Mono.TextEditor.Highlighting; + +using MonoDevelop.Core; +using MonoDevelop.Ide.Editor; using MonoDevelop.Ide.Editor.Highlighting; namespace Mono.TextEditor @@ -79,11 +82,10 @@ namespace Mono.TextEditor static readonly double ZOOM_MIN = System.Math.Pow (ZOOM_FACTOR, ZOOM_MIN_POW); static readonly double ZOOM_MAX = System.Math.Pow (ZOOM_FACTOR, ZOOM_MAX_POW); - + bool isSettingZoom; double myZoom = 1d; public bool ZoomOverride { get; private set; } - public double Zoom { get { if (ZoomOverride) @@ -99,18 +101,23 @@ namespace Mono.TextEditor if ((System.Math.Abs (value - 1d)) < 0.001d) { value = 1d; } - if (ZoomOverride) { - if (myZoom != value) { - myZoom = value; - DisposeFont (); - ZoomChanged?.Invoke (this, EventArgs.Empty); - OnChanged (EventArgs.Empty); + try { + isSettingZoom = true; + if (ZoomOverride) { + if (myZoom != value) { + myZoom = value; + DisposeFont (); + ZoomChanged?.Invoke (this, EventArgs.Empty); + OnChanged (EventArgs.Empty); + } + return; } - return; - } - if (zoom != value) { - zoom = value; - StaticZoomChanged?.Invoke (this, EventArgs.Empty); + if (zoom != value) { + zoom = value; + StaticZoomChanged?.Invoke (this, EventArgs.Empty); + } + } finally { + isSettingZoom = false; } } } @@ -606,14 +613,25 @@ namespace Mono.TextEditor public TextEditorOptions (bool zoomOverride = false) { ZoomOverride = zoomOverride; - if (!ZoomOverride) + if (!ZoomOverride) { StaticZoomChanged += HandleStaticZoomChanged; + TextEditorFactory.ZoomLevel.Changed += HandleConfigurationZoomLevelChanged; + } + } + + void HandleConfigurationZoomLevelChanged (object sender, EventArgs e) + { + // Check for zoom level changes originating from outside old editor + if (!isSettingZoom) + Zoom = TextEditorFactory.ZoomLevel; } public virtual void Dispose () { - if (!ZoomOverride) + if (!ZoomOverride) { StaticZoomChanged -= HandleStaticZoomChanged; + TextEditorFactory.ZoomLevel.Changed -= HandleConfigurationZoomLevelChanged; + } } void HandleStaticZoomChanged (object sender, EventArgs e) |