internal TextBufferLocation(TextLine line, int index, int lineNumber, TextBuffer buffer) { this._line = line; this._columnIndex = index; this._lineIndex = lineNumber; this._buffer = buffer; }
private int GetViewIndex(TextLine line, int index) { int num = 0; int num2 = 0; int length = line.Length; char[] data = line.Data; if (data != null) { while (num < index) { if (data[num] == '\t') { num2 += this.TabSize - (num2 % this.TabSize); } else { num2++; } num++; } } return num2; }
private int GetActualIndex(TextLine line, int xPos) { int index = 0; int num2 = 0; int length = line.Length; char[] data = line.Data; int textWidth; Interop.SIZE size; while (index < length) { if (data[index] == '\t') { num2 += this.TabSize - (num2 % this.TabSize); } else { num2++; } size = this.MeasureString(data, this.ViewLeftIndex, num2 - this.ViewLeftIndex); textWidth = size.x - (this._fontWidth / 2); //textWidth = (((num2 - this.ViewLeftIndex) * this._fontWidth) - (this._fontWidth / 2)); if (xPos < (((textWidth + this.MarginPadding) + this._lineNumbersWidth) + this.MarginWidth)) { return index; } index++; } return index; }
private bool SplitLine(TextLine line, int lineNum, int index, bool isBatching) { if ((index > line.Length) || (index < 0)) { return false; } char[] data = line.Data; this.InsertLine(line, lineNum, new TextLine(data, index, line.Length - index), isBatching); line.Delete(index); return true; }
private bool MergeWithNextLine(TextBufferLocation location) { int lineIndex = location.LineIndex; int columnIndex = location.ColumnIndex; TextLine line = location.Line; TextLine next = line.Next; if ((line == null) || (next == null)) { return false; } int length = line.Length; char[] data = next.Data; int num2 = next.Length; if ((data != null) && (num2 > 0)) { line.Append(data, num2); if (line.Length > this._maxLineLength) { this._maxLineLength = line.Length; this._maxLine = line; } } location.MoveDown(1); this.DeleteLine(location); location.ColumnIndex = length; return true; }
private void InsertText(TextBufferLocation location, ArrayList textList, bool addToUndo, bool loading) { if (!this._undoing) { this.RedoStack.Clear(); } int count = textList.Count; if (count >= 1) { TextLine line = location.Line; int lineIndex = location.LineIndex; int columnIndex = location.ColumnIndex; TextLine next = line; int lineNum = lineIndex; int index = columnIndex; int lineIndexDelta = 0; bool flag = columnIndex < line.Length; for (int i = 0; i < count; i++) { char[] chars = (char[]) textList[i]; int length = chars.Length; int num9 = 0; if (i > 0) { next = next.Next; lineNum++; } if (length > 0) { next.Insert(index, chars, 0, length); if (next == this._last.Line) { this._last.ColumnIndex = next.Length; } num9 = next.Length; if (num9 > this._maxLineLength) { this._maxLineLength = num9; this._maxLine = next; } index += length; } if (i < (count - 1)) { if (flag) { this.SplitLine(next, lineNum, index, true); } else { this.InsertLine(next, lineNum, true); } lineIndexDelta++; index = 0; } } this.FixLocationLineNumbers(lineIndex, lineIndexDelta, next, lineNum, index); this._lineCount += lineIndexDelta; this._last.MoveDown(lineIndexDelta); this._last.ColumnIndex = this._last.Line.Length; if (addToUndo) { this.AddUndo(4, lineIndex, columnIndex, lineNum, index, textList); } if (!loading) { this.OnTextBufferChanged(new TextBufferEventArgs(lineIndex, columnIndex, lineIndex, columnIndex, lineNum, index)); } location.SetLine(next, lineNum); location.ColumnIndex = index; } }
private void InsertLine(TextLine line, int lineNum, TextLine newLine, bool isBatching) { TextLine next = line.Next; line.Next = newLine; newLine.Previous = line; newLine.Next = next; if (next != null) { next.Previous = newLine; } if (!isBatching) { if (next == null) { this._last.SetLine(newLine, lineNum + 1); this._last.ColumnIndex = this._last.Line.Length; } this._lineCount++; } }
public int MoveUp(int lines) { int num = 0; TextLine previous = this._line; int lineIndex = this._lineIndex; while ((num < lines) && (previous != null)) { previous = previous.Previous; if (previous != null) { this._line = previous; lineIndex--; num++; } } this.BeginUpdate(); try { if (this.ColumnIndex > this._line.Length) { this.ColumnIndex = this._line.Length; } this.UpdateLineIndex(lineIndex); } finally { this.EndUpdate(); } return num; }
private void InsertLine(TextLine line, int lineNum) { this.InsertLine(line, lineNum, new TextLine(), false); }
private bool InsertChar(TextBufferLocation location, char c, bool addToUndo) { if (!this._undoing) { this.RedoStack.Clear(); } TextLine line = location.Line; int columnIndex = location.ColumnIndex; if (columnIndex == line.Length) { line.Append(c); } else { line.Insert(columnIndex, c); } if (line == this._last.Line) { this._last.ColumnIndex = line.Length; } if (line.Length > this._maxLineLength) { this._maxLineLength = line.Length; this._maxLine = line; } if (addToUndo) { this.AddUndo(1, location.LineIndex, columnIndex, c); } int lineIndex = location.LineIndex; this.OnTextBufferChanged(new TextBufferEventArgs(lineIndex, columnIndex, lineIndex, columnIndex, lineIndex, columnIndex + 1)); location.ColumnIndex++; return true; }
private void Initialize() { this.UndoStack.Clear(); this.RedoStack.Clear(); TextLine line = new TextLine(); this._first = new TextBufferLocation(line, 0, 0, this); this.LocationList.Clear(); this._last = this.CreateTextBufferLocation(); this._lineCount = 1; }
private void FixLocationLineNumbers(int startLineIndex, int lineIndexDelta, TextLine defaultLine, int defaultLineIndex, int defaultIndex) { foreach (TextBufferLocation location in this.LocationList) { if (location.LineIndex > startLineIndex) { if ((location.LineIndex + lineIndexDelta) <= startLineIndex) { location.SetLine(defaultLine, defaultLineIndex); location.ColumnIndex = defaultIndex; } else { location.UpdateLineIndex(location.LineIndex + lineIndexDelta); } } } }
private int CountScopes(TextLine s) { int num = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == '{') { num++; } else if (s[i] == '}') { num--; } } return num; }
internal void SetLine(TextLine line, int lineIndex) { this._line = line; if (this.ColumnIndex > this._line.Length) { this.ColumnIndex = this._line.Length; } this.UpdateLineIndex(lineIndex); }
private unsafe void PaintTextLine(TextLine line, int lineNum, IntPtr hdc, int yPos, int startIndex) { try { if (this.LineNumbersVisible) { this.ColorTable[4].SetupHdc(hdc); string str = (lineNum + 1).ToString(); int length = str.Length; int num2 = (5 - length) * this._fontWidth; Interop.RECT lpRect = new Interop.RECT(this.MarginWidth, yPos, this.MarginWidth + this._lineNumbersWidth, yPos + this._fontHeight); fixed (char* chRef = str.ToCharArray()) { Interop.ExtTextOutW(hdc, this.MarginWidth + num2, yPos, 2, ref lpRect, (IntPtr)chRef, length, null); } } char[] chars = null; byte[] colors = null; if (line.Length > 0) { int num3 = 0; char[] data = line.Data; byte[] attributes = line.Attributes; int capacity = line.Length * 2; StringBuilder builder = new StringBuilder(capacity); MemoryStream stream = new MemoryStream(capacity); for (int i = 0; i < line.Length; i++) { if (data[i] == '\t') { int num6 = this.TabSize - (num3 % this.TabSize); for (int j = 0; j < num6; j++) { if (this._owner.ShowWhitespace) { builder.Append('→'); } else { builder.Append(' '); } stream.WriteByte(attributes[i]); } num3 += num6; } else { if (this._owner.ShowWhitespace && (data[i] == ' ')) { builder.Append('\x00b7'); } else { builder.Append(data[i]); } stream.WriteByte(attributes[i]); num3++; } } stream.WriteByte(attributes[data.Length]); chars = builder.ToString().ToCharArray(); colors = stream.ToArray(); } else { colors = new byte[0]; chars = new char[0]; } if (this._selectionExists) { if (this._selection.IsSingleLine) { if (lineNum == this._selection.Start.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.Start.ColumnIndex), startIndex), chars.Length); int minLenght = Math.Min(Math.Max(startIndex, this.GetViewIndex(line, this._selection.End.ColumnIndex)), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; //int textWidth = Math.Max(0, endIndex - startIndex) * this._fontWidth; int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, false); rectLeft += textWidth; //textWidth = Math.Max(0, minLenght - endIndex) * this._fontWidth; textWidth = this.MeasureString(hdc, chars, endIndex, minLenght - endIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, endIndex, minLenght, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, minLenght, chars.Length, false); return; } } else { // 已选择文本中的第一行 if (lineNum == this._selection.Start.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.Start.ColumnIndex), startIndex), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; // 先画出行前未选中的文本 int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; //int textWidth = Math.Max(0, endIndex - startIndex) * this._fontWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, false); rectLeft += textWidth; // 然后画出选中的文本 textWidth = this.MeasureString(hdc, chars, endIndex, chars.Length - endIndex).x; if (startIndex <= chars.Length) { textWidth += this._fontWidth; } this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, endIndex, chars.Length, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, 0, 0, false); return; } // 已选择文本中的最后一行 if (lineNum == this._selection.End.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.End.ColumnIndex), startIndex), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; //int num20 = Math.Max(0, num17 - startIndex) * this._fontWidth; int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, endIndex, chars.Length, false); return; } // 选中文本的中间行 if ((lineNum > this._selection.Start.LineIndex) && (lineNum < this._selection.End.LineIndex)) { int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; int textWidth = this.MeasureString(hdc, chars, startIndex, chars.Length - startIndex).x; if (startIndex <= chars.Length) { textWidth += this._fontWidth; } this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, chars.Length, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, 0, 0, false); return; } } } startIndex = Math.Min(startIndex, chars.Length); this.PaintColoredText(chars, colors, hdc, (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding, base.Width - this.VerticalScrollBarWidth, yPos, startIndex, chars.Length, false); } catch (Exception) { throw; } }
private void InsertLine(TextLine line, int lineNum, bool isBatching) { this.InsertLine(line, lineNum, new TextLine(), isBatching); }
private int CountLeadingSpace(TextLine s) { int num = 0; int num2 = 0; int tabSize = this._view.TabSize; while (num < s.Length) { if (s[num] == '\t') { num2 = ((num2 + tabSize) / tabSize) * tabSize; } else { if (s[num] != ' ') { return num2; } num2++; } num++; } return num2; }
public int MoveDown(int lines) { int num = 0; TextLine next = this._line; int lineIndex = this._lineIndex; while ((num < lines) && (next != null)) { next = next.Next; if (next != null) { this._line = next; lineIndex++; num++; } } this.BeginUpdate(); try { if (this.ColumnIndex > this._line.Length) { this.ColumnIndex = this._line.Length; } this.UpdateLineIndex(lineIndex); } finally { this.EndUpdate(); } return num; }