Example #1
0
        private ISmartIndent GetSmartIndent(ITextView textView)
        {
            return(textView.Properties.GetOrCreateSingletonProperty <ISmartIndent>(typeof(SmartIndentationService), delegate
            {
                EventHandler <TextDataModelContentTypeChangedEventArgs> onContentTypeChanged = null;
                EventHandler onClosed = null;

                Action disconnect = delegate()
                {
                    ISmartIndent currentSmartIndent = (ISmartIndent)textView.Properties[typeof(SmartIndentationService)];
                    textView.Properties.RemoveProperty(typeof(SmartIndentationService));
                    currentSmartIndent.Dispose();

                    textView.TextDataModel.ContentTypeChanged -= onContentTypeChanged;
                    textView.Closed -= onClosed;
                };

                onContentTypeChanged = delegate(object sender, TextDataModelContentTypeChangedEventArgs e)
                {
                    disconnect();
                };

                onClosed = delegate(object sender, EventArgs e)
                {
                    disconnect();
                };

                textView.TextDataModel.ContentTypeChanged += onContentTypeChanged;
                textView.Closed += onClosed;

                return CreateSmartIndent(textView);
            }));
        }
			public Helper(SmartIndentationService smartIndentationService, ITextView textView) {
				this.textView = textView;

				textView.Closed += TextView_Closed;
				textView.Options.OptionChanged += Options_OptionChanged;
				textView.TextDataModel.ContentTypeChanged += TextDataModel_ContentTypeChanged;
				SmartIndent = smartIndentationService.CreateSmartIndent(textView);
			}
            public Helper(SmartIndentationService smartIndentationService, ITextView textView)
            {
                this.textView = textView;

                textView.Closed += TextView_Closed;
                textView.Options.OptionChanged            += Options_OptionChanged;
                textView.TextDataModel.ContentTypeChanged += TextDataModel_ContentTypeChanged;
                SmartIndent = smartIndentationService.CreateSmartIndent(textView);
            }
Example #4
0
        public SmartIndent(ITextView textView, IServiceContainer services)
        {
            _textView = textView;
            // In markdown indent is default. In R block delegate to the R indenter.
            var locator = services.GetService <IContentTypeServiceLocator>();
            var sip     = locator.GetService <ISmartIndentProvider>(RContentTypeDefinition.ContentType);

            _smartIndent = sip.CreateSmartIndent(_textView);
        }
Example #5
0
        private int?GetSmartIndent(string content, int lineNumber)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = EditorShell.Current.ExportProvider.GetExport <ISmartIndentProvider>().Value;
            ISmartIndent         indenter = provider.CreateSmartIndent(textView);

            return(indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber)));
        }
Example #6
0
        public void Scope(string content, int lineNum, int expectedIndent)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = _exportProvider.GetExportedValue <ISmartIndentProvider>();
            ISmartIndent         indenter = provider.CreateSmartIndent(textView);
            int?indent = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNum));

            indent.Should().HaveValue().And.Be(expectedIndent);
        }
Example #7
0
        public void Scope(string content, int lineNum, int expectedIndent)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            var          cs       = _services.GetService <ICompositionService>();
            var          composer = new ContentTypeImportComposer <ISmartIndentProvider>(cs);
            var          provider = composer.GetImport(RContentTypeDefinition.ContentType);
            ISmartIndent indenter = provider.CreateSmartIndent(textView);
            int?         indent   = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNum));

            indent.Should().HaveValue().And.Be(expectedIndent);
        }
Example #8
0
 private InteractiveSmartIndenter(IContentType contentType, ITextView view, ISmartIndentProvider provider)
 {
     this.contentType = contentType;
     this.view        = view;
     this.indenter    = provider.CreateSmartIndent(view);
 }
 private InteractiveSmartIndenter(IContentType contentType, ITextView view, ISmartIndentProvider provider)
 {
     this.contentType = contentType;
     this.view = view;
     this.indenter = provider.CreateSmartIndent(view);
 }