Inheritance: IDisposable
        public static CommandRange InnerBlock(TextEditorData editor, char openingChar, char closingChar)
        {
            var range = Block(editor, openingChar, closingChar);
            if (range.Length == 0)
                return CommandRange.Empty;
            int start = range.Start + 1;
            int end = range.End - 2;
            var line = editor.GetLine(editor.OffsetToLineNumber(range.Start));

            // exclude newline if it comes just after opening char
            if (line.EndOffsetIncludingDelimiter - start <= line.DelimiterLength)
                start += line.DelimiterLength;

            // exclude whitespace that comes just before the closing char...
            line = editor.GetLine(editor.OffsetToLineNumber(range.End));
            while (Char.IsWhiteSpace(editor.Text[end]) && end >= line.Offset)
                end--;
            //.. but only if newline comes after it
            if (end >= line.Offset)
                end = range.End - 2;
            else
                end -= line.PreviousLine.DelimiterLength;

            if (start > end + 1)
                return new CommandRange(start, start);

            return new CommandRange(start, end+1);
        }
Example #2
1
		public override void CorrectIndenting (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			TextEditorData data, int line)
		{
			DocumentLine lineSegment = data.Document.GetLine (line);
			if (lineSegment == null)
				return;

			try {
				var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
				var tracker = new CSharpIndentEngine (data.Document, data.CreateNRefactoryTextEditorOptions (),  policy.CreateOptions ());

				tracker.Update (lineSegment.Offset);
				for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++) {
					tracker.Push (data.Document.GetCharAt (i));
				}

				string curIndent = lineSegment.GetIndentation (data.Document);

				int nlwsp = curIndent.Length;
				if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
					// Possibly replace the indent
					string newIndent = tracker.ThisLineIndent;
					if (newIndent != curIndent) 
						data.Replace (lineSegment.Offset, nlwsp, newIndent);
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while indenting", e);
			}
		}
Example #3
1
        /// <summary>
        /// Used for formatting the entire document
        /// </summary>
        public override string FormatText(PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, string input, int startOffset, int endOffset)
        {
            var policy = policyParent.Get<DFormattingPolicy> (mimeTypeChain);
            var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
            var data = new TextEditorData{ Text = input };

            if(IndentCorrectionOnly)
            {
                using(var s = data.OpenStream())
                    using(var r = new StreamReader(s))
                        D_Parser.Formatting.Indent.IndentEngineWrapper.CorrectIndent(r, startOffset, endOffset, data.Document.Replace, policy.Options, new TextStyleAdapter(textPolicy));
                return data.Text;
            }

            var ast = DParser.ParseString(input, false, true) as DModule;
            var formattingVisitor = new DFormattingVisitor(policy.Options, new DocAdapt(data.Document), ast, new TextStyleAdapter(textPolicy));

            // Only clip to a region if it's necessary
            if(startOffset > 0 || endOffset < input.Length-1)
            {
                formattingVisitor.CheckFormattingBoundaries = true;
                var dl = data.Document.OffsetToLocation(startOffset);
                formattingVisitor.FormattingStartLocation = new D_Parser.Dom.CodeLocation(dl.Column, dl.Line);
                dl = data.Document.OffsetToLocation(endOffset);
                formattingVisitor.FormattingEndLocation = new D_Parser.Dom.CodeLocation(dl.Column, dl.Line);
            }

            formattingVisitor.WalkThroughAst();

            formattingVisitor.ApplyChanges(data.Document.Replace);

            return data.Text;
        }
		public static void Format (TextEditorData data, ProjectDom dom, DomLocation location, bool correctBlankLines)
		{
			PolicyContainer policyParent = dom != null && dom.Project != null? dom.Project.Policies
				: PolicyService.DefaultPolicies;
			var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
			Format (policyParent, mimeTypeChain, data, dom, location, correctBlankLines);
		}
		static void RemoveCharBeforCaret (TextEditorData data)
		{
			if (!data.IsSomethingSelected && MonoDevelop.Ide.Editor.DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket) {
				if (data.Caret.Offset > 0) {
					var line = data.GetLine (data.Caret.Line);
					var stack = line.StartSpan.Clone();
					if (stack.Any (s => s.Color == "string.other")) {
						DeleteActions.Backspace (data);
						return;
					}
					stack = line.StartSpan.Clone();
					if (stack.Any (s => s.Color == "string.other")) {
						DeleteActions.Backspace (data);
						return;
					}
					
					char ch = data.Document.GetCharAt (data.Caret.Offset - 1);
					int idx = open.IndexOf (ch);
					
					if (idx >= 0) {
						int nextCharOffset = GetNextNonWsCharOffset (data, data.Caret.Offset);
						if (nextCharOffset >= 0 && closing[idx] == data.Document.GetCharAt (nextCharOffset)) {
							data.Remove (data.Caret.Offset, nextCharOffset - data.Caret.Offset + 1);
						}
					}
				}
			}
			DeleteActions.Backspace (data);
		}
        public static CommandRange QuotedString(TextEditorData editor, char quotationChar)
        {
            var start = editor.Caret.Offset;
            var end = editor.Caret.Offset;
            var lineOffset = editor.GetLine(editor.Caret.Line).Offset;
            var lineEndOffset = editor.GetLine(editor.Caret.Line).EndOffset - 1; // Line includes \n
            if (editor.Text[start] == quotationChar)
            {
                // Check if we're on closing char
                start = lineOffset;
                var openingCandidate = -1;
                while (start < end)
                {
                    if (editor.Text[start] == quotationChar & openingCandidate != -1)
                        openingCandidate = -1;
                    else if (editor.Text[start] == quotationChar)
                        openingCandidate = start;
                    start = start + 1;
                }
                if (openingCandidate != -1)
                {
                    start = openingCandidate;
                }
                else
                {
                    // not on closing char, let's find closing one
                    start = editor.Caret.Offset;
                    end = start + 1;
                    while (end < lineEndOffset & editor.Text[end] != quotationChar)
                        end++;
                }
            }
            else
            {
                while (start >= lineOffset & editor.Text[start] != quotationChar)
                    start--;

                while (end < lineEndOffset & editor.Text[end] != quotationChar)
                    end++;
            }

            if (start < 0 || end > lineEndOffset || start == end)
                return CommandRange.Empty;

            var endIncludingTrailingWhiteSpace = end;
            var startIncludingTrailingWhiteSpace = start;

            // expand to include all trailing white space
            while (endIncludingTrailingWhiteSpace < lineEndOffset && Char.IsWhiteSpace(editor.Text[endIncludingTrailingWhiteSpace + 1]))
                endIncludingTrailingWhiteSpace++;

            // if there's no trailing white space then include leading
            if (endIncludingTrailingWhiteSpace == end)
            {
                while (startIncludingTrailingWhiteSpace > lineOffset && Char.IsWhiteSpace(editor.Text[startIncludingTrailingWhiteSpace - 1]))
                    startIncludingTrailingWhiteSpace--;
            }

            return new CommandRange(Math.Min(start, startIncludingTrailingWhiteSpace), Math.Max(end, endIncludingTrailingWhiteSpace) + 1);
        }
		static void TestInsertionPoints (string text)
		{
			TextEditorData data = new TextEditorData ();
			List<InsertionPoint> loc = new List<InsertionPoint> ();
			for (int i = 0; i < text.Length; i++) {
				char ch = text[i];
				if (ch == '@') {
					i++;
					ch = text[i];
					loc.Add (new InsertionPoint (data.Document.OffsetToLocation (data.Document.Length), ch == '3' || ch == '2', ch == '3' || ch == '1'));
				} else {
					data.Insert (data.Document.Length, ch.ToString ());
				}
			}
			var parseResult = new NRefactoryParser ().Parse (null, "a.cs", data.Document.Text);
			
			var foundPoints = HelperMethods.GetInsertionPoints (data.Document, parseResult.CompilationUnit.Types[0]);
			Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match");
			for (int i = 0; i < loc.Count; i++) {
				Console.WriteLine (loc[i] + "/" + foundPoints[i]);
				Assert.AreEqual (loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
				Assert.AreEqual (loc[i].ShouldInsertNewLineAfter, foundPoints[i].ShouldInsertNewLineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
				Assert.AreEqual (loc[i].ShouldInsertNewLineBefore, foundPoints[i].ShouldInsertNewLineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
			}
		}
Example #8
1
		static void RemoveCharBeforCaret (TextEditorData data)
		{
			if (((ISourceEditorOptions)data.Options).AutoInsertMatchingBracket) {
				if (data.Caret.Offset > 0) {
					var line = data.GetLine (data.Caret.Line);
					var stack = line.StartSpan.Clone();
					if (stack.Any (s => s.Color == "string.other")) {
						DeleteActions.Backspace (data);
						return;
					}
					stack = line.StartSpan.Clone();
					if (stack.Any (s => s.Color == "string.other")) {
						DeleteActions.Backspace (data);
						return;
					}
					
					char ch = data.Document.GetCharAt (data.Caret.Offset - 1);
					int idx = open.IndexOf (ch);
					
					if (idx >= 0) {
						int nextCharOffset = GetNextNonWsCharOffset (data, data.Caret.Offset);
						if (nextCharOffset >= 0 && closing[idx] == data.Document.GetCharAt (nextCharOffset)) {
							bool updateToEnd = data.Document.OffsetToLineNumber (nextCharOffset) != data.Caret.Line;
							data.Remove (data.Caret.Offset, nextCharOffset - data.Caret.Offset + 1);
						}
					}
				}
			}
			DeleteActions.Backspace (data);
		}
		public void TestNamespaceBraceStyle ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = @"namespace A
{
namespace B {
	class Test {}
}
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.NamespaceBraceStyle = BraceStyle.EndOfLine;
			policy.ClassBraceStyle = BraceStyle.DoNotChange;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"namespace A {
	namespace B {
		class Test {}
	}
}", data.Document.Text);
			
			policy.NamespaceBraceStyle = BraceStyle.NextLineShifted;
			compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"namespace A
	{
	namespace B
		{
		class Test {}
		}
	}", data.Document.Text);
		}
		List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator)
		{
			if (DomMethodNodeBuilder.HandleSourceCodeEntity (navigator, data)) 
				return null;
			var field = CecilLoader.GetCecilObject ((IUnresolvedField)navigator.DataItem);
			return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleField (field));
		}
Example #11
1
        public void LoadMark(TextEditorData data)
        {
            // remember where the caret currently is
            int lineNumber = data.Caret.Line;
            int colNumber = data.Caret.Column;

            // get the line number stored with this mark
            int x = (base.LineSegment == null)? 1 : base.LineSegment.LineNumber;

            // reposition the caret on the stored line
            data.Caret.Line = x;
            int len = base.LineSegment.LengthIncludingDelimiter;
            if (ColumnNumber >= len) {
                // Check if the line has been truncated after the setting the mark
                data.Caret.Column = len - 1;
            } else {
                data.Caret.Column = ColumnNumber;
            }

            if (MarkCharacter == '`') {
                data.Document.RemoveMarker (this);
                base.LineSegment = data.Document.GetLine(lineNumber);
                ColumnNumber = colNumber;
                Console.WriteLine ("Line before jump: {0}", lineNumber);
                data.Document.AddMarker (lineNumber, this);
                data.Document.RequestUpdate (new UpdateAll ());
                data.Document.CommitDocumentUpdate ();
            }
        }
		public void TestIndentClassBody ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = 
@"class Test
{
				Test a;
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.IndentClassBody = true;
			
			CSharp.Dom.CompilationUnit compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
	Test a;
}", data.Document.Text);
			policy.IndentClassBody = false;
			compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new DomIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"class Test
{
Test a;
}", data.Document.Text);
		}
Example #13
1
		public GenerateNamespaceImport GetResult (ProjectDom dom, ICompilationUnit unit, IType type, TextEditorData data)
		{
			GenerateNamespaceImport result;
			if (cache.TryGetValue (type.Namespace, out result))
				return result;
			result = new GenerateNamespaceImport ();
			cache[type.Namespace] = result;
			
			result.InsertNamespace  = false;
			
			DomLocation location = new DomLocation (data.Caret.Line, data.Caret.Column);
			foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) {
				if (u.Namespaces.Any (ns => type.Namespace == ns)) {
					result.GenerateUsing = false;
					return result;
				}
			}
			result.GenerateUsing = true;
			string name = type.DecoratedFullName.Substring (type.Namespace.Length + 1);
			
			foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) {
				foreach (string ns in u.Namespaces) {
					if (dom.SearchType (unit, unit.GetTypeAt (location), unit.GetMemberAt (location), ns + "." + name) != null) {
						result.GenerateUsing = false;
						result.InsertNamespace = true;
						return result;
					}
				}
			}
			return result;
		}
 public static CommandRange InnerQuotedString(TextEditorData editor, char enclosingChar)
 {
     var range = QuotedString(editor, enclosingChar);
     if (range.Length == 0)
         return CommandRange.Empty;
     return new CommandRange(range.Start + 1, range.End - 1);
 }
Example #15
1
		public string FormatText (CSharpFormattingPolicy policy, TextStylePolicy textPolicy, string mimeType, string input, int startOffset, int endOffset)
		{
			var data = new TextEditorData ();
			data.Document.SuppressHighlightUpdate = true;
			data.Document.MimeType = mimeType;
			data.Document.FileName = "toformat.cs";
			if (textPolicy != null) {
				data.Options.TabsToSpaces = textPolicy.TabsToSpaces;
				data.Options.TabSize = textPolicy.TabWidth;
				data.Options.IndentationSize = textPolicy.IndentWidth;
				data.Options.IndentStyle = textPolicy.RemoveTrailingWhitespace ? IndentStyle.Virtual : IndentStyle.Smart;
			}
			data.Text = input;

			// System.Console.WriteLine ("-----");
			// System.Console.WriteLine (data.Text.Replace (" ", ".").Replace ("\t", "->"));
			// System.Console.WriteLine ("-----");

			var parser = new CSharpParser ();
			var compilationUnit = parser.Parse (data);
			bool hadErrors = parser.HasErrors;
			
			if (hadErrors) {
				//				foreach (var e in parser.ErrorReportPrinter.Errors)
				//					Console.WriteLine (e.Message);
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			var originalVersion = data.Document.Version;

			var textEditorOptions = data.CreateNRefactoryTextEditorOptions ();
			var formattingVisitor = new ICSharpCode.NRefactory.CSharp.CSharpFormatter (
				policy.CreateOptions (),
				textEditorOptions
			) {
				FormattingMode = FormattingMode.Intrusive
			};

			var changes = formattingVisitor.AnalyzeFormatting (data.Document, compilationUnit);
			try {
				changes.ApplyChanges (startOffset, endOffset - startOffset);
			} catch (Exception e) {
				LoggingService.LogError ("Error in code formatter", e);
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			// check if the formatter has produced errors
			parser = new CSharpParser ();
			parser.Parse (data);
			if (parser.HasErrors) {
				LoggingService.LogError ("C# formatter produced source code errors. See console for output.");
				return input.Substring (startOffset, Math.Max (0, Math.Min (endOffset, input.Length) - startOffset));
			}

			var currentVersion = data.Document.Version;

			string result = data.GetTextBetween (startOffset, originalVersion.MoveOffsetTo (currentVersion, endOffset, ICSharpCode.NRefactory.Editor.AnchorMovementType.Default));
			data.Dispose ();
			return result;
		}
 public static CommandRange InnerBlock(TextEditorData editor, char openingChar, char closingChar)
 {
     var range = Block(editor, openingChar, closingChar);
     if (range.Length == 0)
         return CommandRange.Empty;
     return new CommandRange(range.Start + 1, range.End - 1);
 }
		public static int RemoveTabInLine (TextEditorData data, DocumentLine line)
		{
			if (line.LengthIncludingDelimiter == 0)
				return 0;
			char ch = data.Document.GetCharAt (line.Offset); 
			if (ch == '\t') {
				data.Remove (line.Offset, 1);
				data.Document.CommitLineUpdate (line);
				return 1;
			} else if (ch == ' ') {
				int removeCount = 0;
				for (int i = 0; i < data.Options.IndentationSize;) {
					ch = data.Document.GetCharAt (line.Offset + i);
					if (ch == ' ') {
						removeCount ++;
						i++;
					} else if (ch == '\t') {
						removeCount ++;
						i += data.Options.TabSize;
					} else {
						break;
					}
				}
				data.Remove (line.Offset, removeCount);
				data.Document.CommitLineUpdate (line);
				return removeCount;
			}
			return 0;
		}
		public HeightTree (TextEditorData editor)
		{
			this.editor = editor;
			this.editor.Document.Splitter.LineRemoved += HandleLineRemoved;
			this.editor.Document.Splitter.LineInserted += HandleLineInserted;
			this.editor.Document.FoldTreeUpdated += HandleFoldTreeUpdated;
		}
		public void TestBlankLinesBeforeUsings ()
		{
			TextEditorData data = new TextEditorData ();
			data.Document.FileName = "a.cs";
			data.Document.Text = @"using System;
using System.Text;
namespace Test
{
}";
			
			CSharpFormattingPolicy policy = new CSharpFormattingPolicy ();
			policy.BlankLinesAfterUsings = 0;
			policy.BlankLinesBeforeUsings = 2;
			var compilationUnit = new CSharpParser ().Parse (data);
			compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
			Assert.AreEqual (@"

using System;
using System.Text;
namespace Test
{
}", data.Document.Text);
			
		policy.BlankLinesBeforeUsings = 0;
		compilationUnit = new CSharpParser ().Parse (data);
		compilationUnit.AcceptVisitor (new AstIndentationVisitor (policy, data), null);
		Assert.AreEqual (@"using System;
using System.Text;
namespace Test
{
}", data.Document.Text);
		}
Example #20
1
		public override void CorrectIndenting (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			TextEditorData data, int line)
		{
			LineSegment lineSegment = data.Document.GetLine (line);
			if (lineSegment == null)
				return;

			var policy = policyParent.Get<CFormattingPolicy> (mimeTypeChain);
			var tracker = new DocumentStateTracker<CIndentEngine> (new CIndentEngine (policy), data);
			tracker.UpdateEngine (lineSegment.Offset);
			for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) {
				tracker.Engine.Push (data.Document.GetCharAt (i));
			}

			string curIndent = lineSegment.GetIndentation (data.Document);

			int nlwsp = curIndent.Length;
			if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
				// Possibly replace the indent
				string newIndent = tracker.Engine.ThisLineIndent;
				if (newIndent != curIndent) 
					data.Replace (lineSegment.Offset, nlwsp, newIndent);
			}
			tracker.Dispose ();
		}
Example #21
1
		public static void Left (TextEditorData data)
		{
			if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
				data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
				data.ClearSelection ();
				return;
			}
			
			LineSegment line = data.Document.GetLine (data.Caret.Line);
			IEnumerable<FoldSegment> foldings = data.Document.GetEndFoldings (line);
			FoldSegment segment = null;
			foreach (FoldSegment folding in foldings) {
				if (folding.IsFolded && folding.EndColumn == data.Caret.Column) {
					segment = folding;
					break;
				}
			}
			if (segment != null) {
				data.Caret.Location = data.Document.OffsetToLocation (segment.StartLine.Offset + segment.Column); 
				return;
			}
			
			if (data.Caret.Column > 0) {
				if (data.Caret.Column > line.EditableLength) {
					data.Caret.Column = line.EditableLength;
				} else {
					data.Caret.Column--;
				}
			} else if (data.Caret.Line > 0) {
				LineSegment prevLine = data.Document.GetLine (data.Caret.Line - 1);
				data.Caret.Location = new DocumentLocation (data.Caret.Line - 1, prevLine.EditableLength);
			}
		}
		public virtual bool GetSelectionSurroundings (TextEditorData textEditorData, uint unicodeKey, out string start, out string end)
		{
			switch ((char)unicodeKey) {
			case '"':
				start = end = "\"";
				return true;
			case '\'':
				start = end = "'";
				return true;
			case '(':
				start = "(";
				end = ")";
				return true;
			case '<':
				start = "<";
				end = ">";
				return true;
			case '[':
				start = "[";
				end = "]";
				return true;
			case '{':
				start = "{";
				end = "}";
				return true;
			default:
				start = end = "";
				return false;
			}
		}
		public static void Left (TextEditorData data)
		{
			if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
				data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
				data.ClearSelection ();
				return;
			}
			
			if (data.Caret.Column > DocumentLocation.MinColumn) {
				DocumentLine line = data.Document.GetLine (data.Caret.Line);
				if (data.Caret.Column > line.Length + 1) {
					if (data.Caret.AllowCaretBehindLineEnd) {
						data.Caret.Column--;
					} else {
						data.Caret.Column = line.Length + 1;
					}
				} else {
					int offset = data.Caret.Offset - 1;
					foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) {
						offset = System.Math.Min (offset, folding.Offset);
					}
					data.Caret.Offset = offset;
				}
			} else if (data.Caret.Line > DocumentLocation.MinLine) {
				DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1);
				var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1);
				if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn)
					nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation));
				data.Caret.Location = nextLocation;
			}
		}
		public NRefactoryIndexerParameterDataProvider (TextEditorData editor, IType type, string resolvedExpression)
		{
//			this.editor = editor;
//			this.type = type;
			this.resolvedExpression = resolvedExpression;
			indexers = new List<IProperty> (type.Properties.Where (p => p.IsIndexer && !p.Name.Contains ('.')));
		}
		DocumentStateTracker<CSharpIndentEngine> CreateTracker (TextEditorData data)
		{
			var policy = PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> ("text/x-csharp");
			var textStylePolicy = PolicyService.InvariantPolicies.Get <TextStylePolicy> ("text/x-csharp");
			var result = new DocumentStateTracker<CSharpIndentEngine> (new CSharpIndentEngine (policy, textStylePolicy), data);
			result.UpdateEngine ();
			return result;
		}
Example #26
0
		public static void GotoPrevious (TextEditorData data)
		{
			int offset = GetPrevOffset (data.Document, data.Caret.Line);
			if (offset < 0)
				offset = GetPrevOffset (data.Document, data.Document.LineCount);
			if (offset >= 0)
				data.Caret.Offset = offset;
		}
Example #27
0
		public static void GotoNext (TextEditorData data)
		{
			int offset = GetNextOffset (data.Document, data.Caret.Line);
			if (offset < 0)
				offset = GetNextOffset (data.Document, -1);
			if (offset >= 0)
				data.Caret.Offset = offset;
		}
Example #28
0
		public static void StartSelection (TextEditorData data)
		{
			data.Caret.PreserveSelection = true;
			if (!data.IsSomethingSelected) {
				data.MainSelection = new Selection (data.Caret.Location, data.Caret.Location);
			}
			data.Caret.AutoScrollToCaret = false;
		}
		public static void GotoMatchingBracket (TextEditorData data)
		{
			int matchingBracketOffset = data.Document.GetMatchingBracketOffset (data.Caret.Offset);
			if (matchingBracketOffset == -1 && data.Caret.Offset > 0)
				matchingBracketOffset = data.Document.GetMatchingBracketOffset (data.Caret.Offset - 1);
			
			if (matchingBracketOffset != -1)
				data.Caret.Offset = matchingBracketOffset;
		}
		InvocationExpression GetInvocation (MonoDevelop.CSharp.Dom.CompilationUnit unit, TextEditorData data)
		{
			var containingNode = unit.GetNodeAt (data.Caret.Line, data.Caret.Column);
			var curNode = containingNode;
			while (curNode != null && !(curNode is InvocationExpression)) {
				curNode = curNode.Parent;
			}
			return curNode as InvocationExpression;
		}