diff options
Diffstat (limited to 'src/Editor/Text/Impl')
5 files changed, 53 insertions, 46 deletions
diff --git a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentService.cs b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentService.cs index 430e947..c6a1704 100644 --- a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentService.cs +++ b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentService.cs @@ -24,7 +24,7 @@ namespace Microsoft.VisualStudio.Text.BraceCompletion.Implementation #region Private Members private ITrackingPoint _trackingPoint; - private ITextView3 _textView; + private ICocoaTextView _textView; private IXPlatAdornmentLayer _adornmentLayer; private readonly IEditorFormatMap _editorFormatMap; private Brush _brush; @@ -33,9 +33,9 @@ namespace Microsoft.VisualStudio.Text.BraceCompletion.Implementation #region Constructors - public BraceCompletionAdornmentService(ITextView3 textView, IEditorFormatMap editorFormatMap) + public BraceCompletionAdornmentService(ITextView textView, IEditorFormatMap editorFormatMap) { - _textView = textView; + _textView = (ICocoaTextView)textView; _editorFormatMap = editorFormatMap; if (_textView == null) diff --git a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentServiceFactory.cs b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentServiceFactory.cs index 6938df8..d5c0b62 100644 --- a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentServiceFactory.cs +++ b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionAdornmentServiceFactory.cs @@ -29,7 +29,7 @@ namespace Microsoft.VisualStudio.Text.BraceCompletion.Implementation { // Get the service from the view's property bag return textView.Properties.GetOrCreateSingletonProperty<IBraceCompletionAdornmentService>( - () => new BraceCompletionAdornmentService((ITextView3)textView, _editorFormatMapService.GetEditorFormatMap(textView))); + () => new BraceCompletionAdornmentService(textView, _editorFormatMapService.GetEditorFormatMap(textView))); } #endregion diff --git a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionImpl.csproj b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionImpl.csproj index bb50037..d8eb0fc 100644 --- a/src/Editor/Text/Impl/BraceCompletion/BraceCompletionImpl.csproj +++ b/src/Editor/Text/Impl/BraceCompletion/BraceCompletionImpl.csproj @@ -28,7 +28,7 @@ <ProjectReference Include="..\..\Def\TextData\TextData.csproj" /> <ProjectReference Include="..\..\Def\TextLogic\TextLogic.csproj" /> <ProjectReference Include="..\..\Def\TextUI\TextUI.csproj" /> - <ProjectReference Include="..\..\Def\TextUIWpf\TextUIWpf.csproj" /> + <ProjectReference Include="..\..\Def\TextUICocoa\TextUICocoa.csproj" /> <ProjectReference Include="..\..\Util\TextDataUtil\TextDataUtil.csproj" /> <ProjectReference Include="..\..\Def\Internal\Internal.csproj" /> </ItemGroup> diff --git a/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs b/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs index 3f6107d..3a2c915 100644 --- a/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs +++ b/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs @@ -27,6 +27,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation using Microsoft.VisualStudio.Text.Tagging; using Microsoft.VisualStudio.Language.Intellisense.Utilities; using Microsoft.VisualStudio.Text.Utilities; + using Microsoft.VisualStudio.Text.Data.Utilities; /// <summary> /// Provides a default operations set on top of the text editor @@ -56,7 +57,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation #region Private Members - readonly ITextView3 _textView; + readonly ITextView _textView; readonly EditorOperationsFactoryService _factory; readonly ITextDocument _textDocument; readonly ITextStructureNavigator _textStructureNavigator; @@ -96,7 +97,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation if (factory == null) throw new ArgumentNullException(nameof(factory)); - _textView = (Microsoft.VisualStudio.Text.Editor.ITextView3) textView; + _textView = textView; _factory = factory; _multiSelectionBroker = _textView.GetMultiSelectionBroker(); _editorPrimitives = factory.EditorPrimitivesProvider.GetViewPrimitives(textView); @@ -3188,14 +3189,20 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation public void ScrollColumnLeft() { - // A column is defined as the width of a space in the default font - _textView.ViewScroller.ScrollViewportHorizontallyByPixels(_textView.FormattedLineSource.ColumnWidth * -1.0); + if (_textView.ViewScroller is IViewScroller2 viewScroller) + { + // A column is defined as the width of a space in the default font + viewScroller.ScrollColumnLeft(); + } } public void ScrollColumnRight() { - // A column is defined as the width of a space in the default font - _textView.ViewScroller.ScrollViewportHorizontallyByPixels(_textView.FormattedLineSource.ColumnWidth); + if (_textView.ViewScroller is IViewScroller2 viewScroller) + { + // A column is defined as the width of a space in the default font + viewScroller.ScrollColumnRight(); + } } public void ScrollLineBottom() @@ -3229,54 +3236,35 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation _undoHistory.CurrentTransaction.AddUndo(beforeTextBufferChangeUndoPrimitive); } - public bool CanZoomIn => CanZoomTo && _textView.ZoomLevel < _textView.Options.GlobalOptions.MaxZoom(); + public bool CanZoomIn => CanZoomTo && _factory.ZoomManager.ZoomLevel(_textView) < _textView.Options.GlobalOptions.MaxZoom(); - public void ZoomIn() - { - if (CanZoomIn) - { - var maxZoom = _textView.Options.GlobalOptions.MaxZoom(); - double zoomLevel = Math.Min(_textView.ZoomLevel * ZoomConstants.ScalingFactor, maxZoom); - if (zoomLevel < maxZoom || Math.Abs(zoomLevel - maxZoom) < 0.00001) - { - _textView.Options.GlobalOptions.SetOptionValue(DefaultTextViewOptions.ZoomLevelId, zoomLevel); - } - } - } + public bool CanZoomOut => CanZoomTo && _factory.ZoomManager.ZoomLevel(_textView) > _textView.Options.GlobalOptions.MinZoom(); - public bool CanZoomOut => CanZoomTo && _textView.ZoomLevel > _textView.Options.GlobalOptions.MinZoom(); + public bool CanZoomTo => _textView.Roles.Contains(PredefinedTextViewRoles.Zoomable); - public void ZoomOut() + public bool CanZoomReset => CanZoomTo && _factory.ZoomManager.ZoomLevel(_textView) != ZoomConstants.DefaultZoom; + + public void ZoomReset() { - if (CanZoomOut) + if (CanZoomReset) { - var minZoom = _textView.Options.GlobalOptions.MinZoom(); - double zoomLevel = Math.Max(_textView.ZoomLevel / ZoomConstants.ScalingFactor, minZoom); - if (zoomLevel > minZoom || Math.Abs(zoomLevel - minZoom) < 0.00001) - { - _textView.Options.GlobalOptions.SetOptionValue(DefaultTextViewOptions.ZoomLevelId, zoomLevel); - } + ZoomTo(ZoomConstants.DefaultZoom); } } - public bool CanZoomTo => _textView.Roles.Contains(PredefinedTextViewRoles.Zoomable); - - public void ZoomTo(double zoomLevel) + public void ZoomIn() { - if (CanZoomTo) - { - _textView.Options.GlobalOptions.SetZoomLevel(zoomLevel); - } + _factory.ZoomManager.ZoomIn(_textView); } - public bool CanZoomReset => CanZoomTo && _textView.ZoomLevel != ZoomConstants.DefaultZoom; + public void ZoomOut() + { + _factory.ZoomManager.ZoomOut(_textView); + } - public void ZoomReset() + public void ZoomTo(double zoomLevel) { - if (CanZoomReset) - { - ZoomTo(ZoomConstants.DefaultZoom); - } + _factory.ZoomManager.ZoomTo(_textView, zoomLevel); } #endregion // IEditorOperations Members @@ -5350,6 +5338,18 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation }); } } + + public string NormalizeNewlinesInString(string text) + { + if (_factory.WhitespaceManagerFactory.TryGetExistingWhitespaceManager(_textView.TextDataModel.DocumentBuffer, out var whitespaceManager)) + { + return whitespaceManager.NewlineState.NormalizeNewlines(text); + } + else + { + return text; + } + } } /// <summary> diff --git a/src/Editor/Text/Impl/EditorOperations/EditorOperationsFactoryService.cs b/src/Editor/Text/Impl/EditorOperations/EditorOperationsFactoryService.cs index b58c2ca..3e39491 100644 --- a/src/Editor/Text/Impl/EditorOperations/EditorOperationsFactoryService.cs +++ b/src/Editor/Text/Impl/EditorOperations/EditorOperationsFactoryService.cs @@ -15,6 +15,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation using Microsoft.VisualStudio.Utilities; using Microsoft.VisualStudio.Text.Outlining; using Microsoft.VisualStudio.Language.Intellisense.Utilities; + using Microsoft.VisualStudio.Text.Document; [Export(typeof(IEditorOperationsFactoryService))] internal sealed class EditorOperationsFactoryService : IEditorOperationsFactoryService @@ -59,6 +60,12 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation [Import(AllowDefault = true)] internal IOutliningManagerService OutliningManagerService { get; set; } + [Import] + internal IWhitespaceManagerFactory WhitespaceManagerFactory { get; set; } + + [Import] + internal ITextViewZoomManager ZoomManager { get; set; } + /// <summary> /// Provides a operations implementation for a given text view. /// </summary> |