void DoReSmartIndent(int cursor) { if (stateTracker.Engine.LineBeganInsideVerbatimString || stateTracker.Engine.LineBeganInsideMultiLineComment) { return; } DocumentLine line = textEditorData.Document.GetLineByOffset(cursor); // stateTracker.UpdateEngine (line.Offset); // Get context to the end of the line w/o changing the main engine's state var ctx = (CSharpIndentEngine)stateTracker.Engine.Clone(); for (int max = cursor; max < line.EndOffset; max++) { ctx.Push(textEditorData.Document.GetCharAt(max)); } int pos = line.Offset; string curIndent = line.GetIndentation(textEditorData.Document); int nlwsp = curIndent.Length; int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!stateTracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < line.LengthIncludingDelimiter && textEditorData.Document.GetCharAt(line.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = ctx.ThisLineIndent; int newIndentLength = newIndent.Length; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } newIndentLength = textEditorData.Replace(pos, nlwsp, newIndent); textEditorData.Document.CommitLineUpdate(textEditorData.Caret.Line); // Engine state is now invalid stateTracker.ResetEngineToPosition(pos); CompletionWindowManager.HideWindow(); } pos += newIndentLength; } else { pos += curIndent.Length; } pos += offset; textEditorData.FixVirtualIndentation(); }
//does re-indenting and cursor positioning void DoReSmartIndent() { string newIndent = string.Empty; int cursor = textEditorData.Caret.Offset; // Get context to the end of the line w/o changing the main engine's state CSharpIndentEngine ctx = (CSharpIndentEngine)stateTracker.Engine.Clone(); LineSegment line = textEditorData.Document.GetLine(textEditorData.Caret.Line); for (int max = line.Offset; max < line.Offset + line.EditableLength; max++) { ctx.Push(textEditorData.Document.GetCharAt(max)); } int pos = line.Offset; string curIndent = line.GetIndentation(textEditorData.Document); int nlwsp = curIndent.Length; int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!stateTracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < line.Length && textEditorData.Document.GetCharAt(line.Offset + nlwsp) == '*')) { // Possibly replace the indent newIndent = ctx.ThisLineIndent; int newIndentLength = newIndent.Length; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } newIndentLength = textEditorData.Replace(pos, nlwsp, newIndent); // Engine state is now invalid stateTracker.ResetEngineToPosition(pos); } pos += newIndentLength; } else { pos += curIndent.Length; } pos += offset; textEditorData.Caret.Offset = pos; }