public override void IndentLines(TextDocument document, int beginLine, int endLine) { if (!SupportMultiLinesIndent(document)) { base.IndentLines(document, beginLine, endLine); return; } DocumentLine line = document.GetLineByNumber(beginLine); int offset = line?.Offset ?? -1; int length = CalcSegmentLength(line, endLine); if ((offset == -1) || (length == 0)) { return; } IndentationCompletedArg eventArg = PrepareIndentationCompletedArg(document); GherkinSimpleParser parser = new GherkinSimpleParser(document); string formatted_text = parser.Format(beginLine, endLine); if (endLine == document.LineCount) { StringBuilder sb = new StringBuilder(formatted_text); sb.TrimEnd().AppendLine(); formatted_text = sb.ToString(); } document.Replace(offset, length, formatted_text); EventAggregator <IndentationCompletedArg> .Instance.Publish(MainEditor, eventArg); }
/// <summary> /// Scroll cursor to original position if the document of this editor has been indented. /// </summary> /// <param name="sender">Indented document</param> /// <param name="arg"></param> private void OnIndentationCompleted(object sender, IndentationCompletedArg arg) { if (sender == TextEditor) { int lineNo = Math.Min(Document.LineCount, arg.Line); var line = Document.GetLineByNumber(lineNo); int column = Math.Min(arg.Column, line.Length); ScrollCursorTo(lineNo, column); } }
private void OnIndentationCompleted(object sender, IndentationCompletedArg arg) { Status = Properties.Resources.Message_PrettyFormatCompleted; }