void RunFormatter(DocumentLocation location) { if (OnTheFlyFormatting && textEditorData != null && !(textEditorData.CurrentMode is TextLinkEditMode) && !(textEditorData.CurrentMode is InsertionCursorEditMode)) { OnTheFlyFormatter.Format(Document, location); } }
async void CompletionWindowManager_WindowClosed(object sender, EventArgs e) { var document = DocumentContext.AnalysisDocument; if (document == null) { return; } var caretPosition = Editor.CaretOffset; var token = await CSharpEditorFormattingService.GetTokenBeforeTheCaretAsync(document, caretPosition, default(CancellationToken)).ConfigureAwait(false); if (token.IsMissing || !token.Parent.IsKind(SyntaxKind.ElseDirectiveTrivia)) { return; } var tokenRange = Microsoft.CodeAnalysis.CSharp.Utilities.FormattingRangeHelper.FindAppropriateRange(token); if (tokenRange == null || !tokenRange.HasValue || tokenRange.Value.Item1.Equals(tokenRange.Value.Item2)) { return; } var value = tokenRange.Value; using (var undo = Editor.OpenUndoGroup()) { OnTheFlyFormatter.Format(Editor, DocumentContext, value.Item1.SpanStart, value.Item2.Span.End, optionSet: optionSet); } }
void RunFormatter(MonoDevelop.Ide.Editor.DocumentLocation location) { if (!OnTheFlyFormatting || Editor == null || Editor.EditMode != EditMode.Edit) { return; } var offset = Editor.LocationToOffset(location); OnTheFlyFormatter.Format(Editor, DocumentContext, offset, offset, optionSet: optionSet); }
/* void TextCut (object sender, ReplaceEventArgs e) * { * if (!string.IsNullOrEmpty (e.Value) || e.Count == 0) * return; * RunFormatterAt (e.Offset); * }*/ void RunFormatterAt(int offset) { if (PropertyService.Get("OnTheFlyFormatting", false) && textEditorData != null && Document != null) { // textEditorData.Document.TextReplaced -= TextCut; ProjectDom dom = Document.Dom; DocumentLocation loc = textEditorData.Document.OffsetToLocation(offset); DomLocation location = new DomLocation(loc.Line, loc.Column); // CSharpFormatter.Format (textEditorData, dom, Document.CompilationUnit, location); OnTheFlyFormatter.Format(Document, dom, location); // textEditorData.Document.TextReplaced += TextCut; } }
void RunFormatter() { if (PropertyService.Get("OnTheFlyFormatting", false) && textEditorData != null && !(textEditorData.CurrentMode is TextLinkEditMode)) { // textEditorData.Document.TextReplaced -= TextCut; ProjectDom dom = ProjectDomService.GetProjectDom(Document.Project); if (dom == null) { dom = ProjectDomService.GetFileDom(Document.FileName); } DomLocation location = new DomLocation(textEditorData.Caret.Location.Line + (lastCharInserted == '\n' ? -1 : 0), textEditorData.Caret.Location.Column); // CSharpFormatter.Format (textEditorData, dom, Document.CompilationUnit, location); OnTheFlyFormatter.Format(Document, dom, location, lastCharInserted == '\n'); // textEditorData.Document.TextReplaced += TextCut; } }
public override void PostFomatPastedText(int insertionOffset, int insertedChars) { if (indent.Editor.Options.IndentStyle == IndentStyle.None || indent.Editor.Options.IndentStyle == IndentStyle.Auto) { return; } if (DefaultSourceEditorOptions.Instance.OnTheFlyFormatting) { OnTheFlyFormatter.Format(indent.Editor, indent.DocumentContext, insertionOffset, insertionOffset + insertedChars); return; } // Just correct the start line of the paste operation - the text is already indented. var curLine = indent.Editor.GetLineByOffset(insertionOffset); var curLineOffset = curLine.Offset; indent.SafeUpdateIndentEngine(curLineOffset); if (!indent.stateTracker.IsInsideOrdinaryCommentOrString) { int pos = curLineOffset; string curIndent = curLine.GetIndentation(indent.Editor); int nlwsp = curIndent.Length; if (!indent.stateTracker.LineBeganInsideMultiLineComment || (nlwsp < curLine.LengthIncludingDelimiter && indent.Editor.GetCharAt(curLineOffset + nlwsp) == '*')) { // Possibly replace the indent indent.SafeUpdateIndentEngine(curLineOffset + curLine.Length); string newIndent = indent.stateTracker.ThisLineIndent; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } indent.Editor.ReplaceText(pos, nlwsp, newIndent); // textEditorData.Document.CommitLineUpdate (textEditorData.CaretLine); } } } indent.Editor.FixVirtualIndentation(); }
async void FormatOnReturn(CancellationToken cancellationToken = default(CancellationToken)) { var document = DocumentContext.AnalysisDocument; if (document == null) { return; } var caretPosition = Editor.CaretOffset; var token = await CSharpEditorFormattingService.GetTokenBeforeTheCaretAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); if (token.IsMissing) { return; } string text = null; if (service.IsInvalidToken(token, ref text)) { return; } // Check to see if the token is ')' and also the parent is a using statement. If not, bail if (CSharpEditorFormattingService.TokenShouldNotFormatOnReturn(token)) { return; } var tokenRange = Microsoft.CodeAnalysis.CSharp.Utilities.FormattingRangeHelper.FindAppropriateRange(token); if (tokenRange == null || !tokenRange.HasValue || tokenRange.Value.Item1.Equals(tokenRange.Value.Item2)) { return; } var value = tokenRange.Value; using (var undo = Editor.OpenUndoGroup()) { OnTheFlyFormatter.Format(Editor, DocumentContext, value.Item1.SpanStart, value.Item2.Span.End, optionSet: optionSet); } }
protected override void OnTheFlyFormatImplementation(TextEditor editor, DocumentContext context, int startOffset, int length) { OnTheFlyFormatter.Format(editor, context, startOffset, startOffset + length); }
public override void OnTheFlyFormat(MonoDevelop.Ide.Gui.Document doc, int startOffset, int endOffset) { OnTheFlyFormatter.Format(doc, startOffset, endOffset); }