static string GetIndent(string text) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = text; string result = null; for (int i = 1; i < doc.LineCount; i++) { string lineIndent = doc.GetLineIndent(i); if (doc.GetLine(i).EditableLength == lineIndent.Length) { continue; } if (result == null || lineIndent.Length < result.Length) { result = lineIndent; } } return(result ?? ""); }
static void CheckStartPoint (Document doc, InsertionPoint point, bool isEndPoint) { LineSegment line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 == point.Location.Column) { int lineNr = point.Location.Line; while (lineNr > 1 && doc.GetLineIndent (lineNr - 1).Length == doc.GetLine (lineNr - 1).EditableLength) { lineNr--; } line = doc.GetLine (lineNr); point.Location = new DocumentLocation (lineNr, doc.GetLineIndent (line).Length + 1); } if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine; if (point.Location.Column < line.EditableLength + 1) point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine; }
static void CheckEndPoint (Document doc, InsertionPoint point, bool isStartPoint) { LineSegment line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = NewLineInsertion.BlankLine; if (point.Location.Column < line.EditableLength + 1) point.LineAfter = NewLineInsertion.Eol; }
static string GetIndent (string text) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); doc.Text = text; string result = null; for (int i = 1; i < doc.LineCount; i++) { string lineIndent = doc.GetLineIndent (i); if (doc.GetLine (i).EditableLength == lineIndent.Length) continue; if (result == null || lineIndent.Length < result.Length) result = lineIndent; } return result ?? ""; }
static InsertionPoint GetInsertionPosition (Document doc, int line, int column) { int bodyEndOffset = doc.LocationToOffset (line, column) + 1; LineSegment curLine = doc.GetLine (line); if (curLine != null) { if (bodyEndOffset < curLine.Offset + curLine.EditableLength) return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine); } LineSegment nextLine = doc.GetLine (line + 1); int endOffset = nextLine != null ? nextLine.Offset : doc.Length; for (int i = bodyEndOffset; i < endOffset; i++) { char ch = doc.GetCharAt (i); if (!char.IsWhiteSpace (ch)) return new InsertionPoint (doc.OffsetToLocation (i), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine); } if (nextLine == null) return new InsertionPoint (doc.OffsetToLocation (bodyEndOffset - 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine); int oldLine = line; while (line < doc.LineCount && doc.GetLineIndent (line + 1).Length == doc.GetLine (line + 1).EditableLength) line++; NewLineInsertion insertBefore = NewLineInsertion.None; NewLineInsertion insertAfter = NewLineInsertion.None; int delta = line - oldLine; int lineNumber = line + 1; if (delta == 0) { insertBefore = NewLineInsertion.Eol; insertAfter = NewLineInsertion.BlankLine; } else if (delta == 1) { insertAfter = NewLineInsertion.BlankLine; } else if (delta == 2) { lineNumber--; insertAfter = NewLineInsertion.BlankLine; } else if (delta >= 3) { lineNumber -= 2; insertAfter = NewLineInsertion.None; } return new InsertionPoint (new DocumentLocation (lineNumber, doc.GetLineIndent (lineNumber).Length + 1), insertBefore, insertAfter); }
static InsertionPoint GetInsertionPosition (Document doc, int line, int column) { LineSegment nextLine = doc.GetLine (line + 1); int bodyEndOffset = doc.LocationToOffset (line, column) + 1; int endOffset = nextLine != null ? nextLine.Offset : doc.Length; for (int i = bodyEndOffset; i < endOffset; i++) { char ch = doc.GetCharAt (i); if (!char.IsWhiteSpace (ch)) return new InsertionPoint (doc.OffsetToLocation (i), true, true); } if (nextLine == null) return new InsertionPoint (doc.OffsetToLocation (bodyEndOffset - 1), true, true); int oldLine = line; bool curLineEmpty = false; if (doc.GetLineIndent (nextLine).Length == nextLine.EditableLength) { curLineEmpty = true; while (line + 2 < doc.LineCount && doc.GetLineIndent (line + 2).Length == doc.GetLine (line + 2).EditableLength) line++; } bool insertBefore = !curLineEmpty && line - oldLine <= 1; bool insertAfter = line - oldLine == 0; // if (curLineEmpty) // line++; int lineNumber = line + 1; return new InsertionPoint (new DocumentLocation (lineNumber, doc.GetLineIndent (lineNumber).Length), insertBefore, insertAfter); }
static void CheckStartPoint (Document doc, InsertionPoint point) { LineSegment line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length < point.Location.Column) point.ShouldInsertNewLineBefore = true; if (point.Location.Column < line.EditableLength) point.ShouldInsertNewLineAfter = true; }