public void RawlyIndentLine(string indentString, ICSharpCode.AvalonEdit.Document.TextDocument document, DocumentLine line) { if (!_doBeginUpdateManually) { document.BeginUpdate(); } // 1) int prevInd = 0; int curOff = line.Offset; if (curOff < document.TextLength) { char curChar = '\0'; while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t')) { prevInd++; curOff++; } document.Remove(line.Offset, prevInd); } document.Insert(line.Offset, indentString); if (!_doBeginUpdateManually) { document.EndUpdate(); } }
public void AnchorsSurviveDeletion() { document.Text = new string(' ', 10); TextAnchor[] a1 = new TextAnchor[11]; TextAnchor[] a2 = new TextAnchor[11]; for (int i = 0; i < 11; i++) { //Console.WriteLine("Insert first at i = " + i); a1[i] = document.CreateAnchor(i); a1[i].SurviveDeletion = true; //Console.WriteLine(document.GetTextAnchorTreeAsString()); //Console.WriteLine("Insert second at i = " + i); a2[i] = document.CreateAnchor(i); a2[i].SurviveDeletion = false; //Console.WriteLine(document.GetTextAnchorTreeAsString()); } for (int i = 0; i < 11; i++) { Assert.AreEqual(i, a1[i].Offset); Assert.AreEqual(i, a2[i].Offset); } document.Remove(1, 8); for (int i = 0; i < 11; i++) { if (i <= 1) { Assert.IsFalse(a1[i].IsDeleted); Assert.IsFalse(a2[i].IsDeleted); Assert.AreEqual(i, a1[i].Offset); Assert.AreEqual(i, a2[i].Offset); } else if (i <= 8) { Assert.IsFalse(a1[i].IsDeleted); Assert.IsTrue(a2[i].IsDeleted); Assert.AreEqual(1, a1[i].Offset); } else { Assert.IsFalse(a1[i].IsDeleted); Assert.IsFalse(a2[i].IsDeleted); Assert.AreEqual(i - 8, a1[i].Offset); Assert.AreEqual(i - 8, a2[i].Offset); } } }
public void RemoveInCollapsedSection() { CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(3), document.GetLineByNumber(7)); int line4Offset = document.GetLineByNumber(4).Offset; int line6Offset = document.GetLineByNumber(6).Offset; document.Remove(line4Offset, line6Offset - line4Offset); for (int i = 1; i < 3; i++) { Assert.IsFalse(heightTree.GetIsCollapsed(i)); } for (int i = 3; i <= 5; i++) { Assert.IsTrue(heightTree.GetIsCollapsed(i)); } for (int i = 6; i <= 8; i++) { Assert.IsFalse(heightTree.GetIsCollapsed(i)); } CheckHeights(); }
public void RawlyIndentLine(int tabsToInsert, ICSharpCode.AvalonEdit.Document.TextDocument document, DocumentLine line) { if (!_doBeginUpdateManually) { document.BeginUpdate(); } /* * 1) Remove old indentation * 2) Insert new one */ // 1) int prevInd = 0; int curOff = line.Offset; if (curOff < document.TextLength) { char curChar = '\0'; while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t')) { prevInd++; curOff++; } document.Remove(line.Offset, prevInd); } // 2) string indentString = ""; for (int i = 0; i < tabsToInsert; i++) { indentString += dEditor.Editor.Options.IndentationString; } document.Insert(line.Offset, indentString); if (!_doBeginUpdateManually) { document.EndUpdate(); } }
public void TestLinesRemoved() { document.Remove(5, 4); CheckHeights(); }
public void LineIndexOfTest() { DocumentLine line = document.GetLineByNumber(1); Assert.AreEqual(0, document.Lines.IndexOf(line)); DocumentLine lineFromOtherDocument = new TextDocument().GetLineByNumber(1); Assert.AreEqual(-1, document.Lines.IndexOf(lineFromOtherDocument)); document.Text = "a\nb\nc"; DocumentLine middleLine = document.GetLineByNumber(2); Assert.AreEqual(1, document.Lines.IndexOf(middleLine)); document.Remove(1, 3); Assert.IsTrue(middleLine.IsDeleted); Assert.AreEqual(-1, document.Lines.IndexOf(middleLine)); }
public void RawlyIndentLine(int tabsToInsert, TextDocument document, DocumentLine line) { if (!_doBeginUpdateManually) document.BeginUpdate(); /* * 1) Remove old indentation * 2) Insert new one */ // 1) int prevInd = 0; int curOff = line.Offset; if (curOff < document.TextLength) { char curChar = '\0'; while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t')) { prevInd++; curOff++; } document.Remove(line.Offset, prevInd); } // 2) string indentString = ""; for (int i = 0; i < tabsToInsert; i++) indentString += dEditor.Editor.Options.IndentationString; document.Insert(line.Offset, indentString); if (!_doBeginUpdateManually) document.EndUpdate(); }
private void DeleteComment(TextDocument doc, DocumentLine line) { if (doc.TextLength < 2) return; if (doc.GetText(line.Offset, line.EndOffset - line.Offset).TrimStart().StartsWith(FbCommentString)) { var idx = doc.Text.IndexOf(FbCommentString, line.Offset); doc.Remove(idx, FbCommentString.Length); } }