public AutoCompleteForm(TextView view, TextControl owner, TextBufferLocation location, ITextAutoCompletionList list) { this.InitializeComponent(); this._pickedItem = string.Empty; this._list = list; foreach (TextAutoCompletionItem item in list.Items) { this._itemList.Items.Add(item); } this._view = view; this._nextHandler = this._view.AddCommandHandler(this); this._owner = owner; if (location.ColumnIndex == location.Line.Length) { this._startLocation = location.Clone(); } else { using (TextBufferSpan span = this._view.GetWordSpan(location)) { this._startLocation = span.Start.Clone(); } } this._timer = new Timer(); this._timer.Interval = 500; this._timer.Tick += new EventHandler(this.OnTimerTick); }
private void TrimTrailingWhitespace(TextBufferLocation location) { this._trimmingWhitespace = true; try { TextLine line = location.Line; int length = line.Length; int num2 = length; while ((num2 > 0) && char.IsWhiteSpace(line[num2 - 1])) { num2--; } if (length != num2) { using (TextBufferLocation location2 = location.Clone()) { location2.ColumnIndex = num2; location.ColumnIndex = length; this._buffer.DeleteText(new TextBufferSpan(location2, location)); } } } finally { this._trimmingWhitespace = false; } }
private TextBufferSpan CreateStringSpan(TextBufferLocation location, int stringLength) { TextBufferLocation end = location.Clone(); end.ColumnIndex += stringLength; return new TextBufferSpan(location, end); }
public virtual TextBufferSpan GetWordSpan(TextBufferLocation location, WordType type) { TextBufferLocation location4; TextLine line2; int columnIndex; if (type != WordType.Previous) { if (type != WordType.Next) { if (location.Line.Length == 0) { return null; } TextBufferLocation start = location.Clone(); if (start.ColumnIndex >= start.Line.Length) { start.ColumnIndex = start.Line.Length - 1; } TextBufferLocation location7 = location.Clone(); if (!this.IsSeperatorChar(start.Line[start.ColumnIndex])) { while ((start.ColumnIndex > 0) && !this.IsSeperatorChar(start.Line[start.ColumnIndex - 1])) { start.ColumnIndex--; } while ((location7.ColumnIndex < location7.Line.Length) && !this.IsSeperatorChar(location7.Line[location7.ColumnIndex])) { location7.ColumnIndex++; } } else { while (((start.ColumnIndex > 0) && this.IsSeperatorChar(start.Line[start.ColumnIndex - 1])) && !char.IsWhiteSpace(start.Line[start.ColumnIndex - 1])) { start.ColumnIndex--; } while (((location7.ColumnIndex < location7.Line.Length) && this.IsSeperatorChar(location7.Line[location7.ColumnIndex])) && !char.IsWhiteSpace(start.Line[location7.ColumnIndex])) { location7.ColumnIndex++; } } return new TextBufferSpan(start, location7); } location4 = location.Clone(); line2 = location4.Line; columnIndex = location4.ColumnIndex; bool flag = false; if (columnIndex == line2.Length) { if (location4.MoveDown(1) > 0) { line2 = location4.Line; columnIndex = 0; flag = true; } else { columnIndex = line2.Length; } } if (!flag) { if ((columnIndex >= line2.Length) || !this.IsSeperatorChar(line2[columnIndex])) { while ((columnIndex < line2.Length) && !this.IsSeperatorChar(line2[columnIndex])) { columnIndex++; } } else { while ((columnIndex < line2.Length) && this.IsSeperatorChar(line2[columnIndex])) { columnIndex++; } } } } else { TextBufferLocation location2 = location.Clone(); TextLine line = location2.Line; int num = location2.ColumnIndex; TextBufferLocation location3 = location2.Clone(); if (num != 0) { while ((num > 0) && char.IsWhiteSpace(line[num - 1])) { num--; } if ((num <= 0) || !this.IsSeperatorChar(line[num - 1])) { while ((num > 0) && !this.IsSeperatorChar(line[num - 1])) { num--; } } else { while ((num > 0) && this.IsSeperatorChar(line[num - 1])) { num--; } } } else { if (location2.MoveUp(1) > 0) { location2.ColumnIndex = location2.Line.Length; return new TextBufferSpan(location2, location3); } location2.ColumnIndex = 0; return new TextBufferSpan(location2, location3); } location2.ColumnIndex = num; return new TextBufferSpan(location2, location3); } while ((columnIndex < line2.Length) && char.IsWhiteSpace(line2[columnIndex])) { columnIndex++; } location4.ColumnIndex = columnIndex; TextBufferLocation end = location4.Clone(); if ((end.ColumnIndex >= end.Line.Length) || !this.IsSeperatorChar(end.Line[end.ColumnIndex])) { while ((end.ColumnIndex < end.Line.Length) && !this.IsSeperatorChar(end.Line[end.ColumnIndex])) { end.ColumnIndex++; } } else { while ((end.ColumnIndex < end.Line.Length) && this.IsSeperatorChar(end.Line[end.ColumnIndex])) { end.ColumnIndex++; } } return new TextBufferSpan(location4, end); }
public TextBufferSpan Find(TextBufferLocation startLocation, TextBufferLocation endLocation, string searchString, bool matchCase, bool wholeWord, bool searchUp) { if (startLocation == null) { throw new ArgumentNullException("startLocation"); } if (endLocation == null) { throw new ArgumentNullException("endLocation"); } TextBufferLocation location = null; int lineIndex = 0; if (searchUp) { location = endLocation.Clone(); lineIndex = startLocation.LineIndex; } else { location = startLocation.Clone(); lineIndex = endLocation.LineIndex; } TextLine line = location.Line; int length = searchString.Length; int columnIndex = location.ColumnIndex; if (searchUp) { if (columnIndex == 0) { location.MoveUp(1); line = location.Line; columnIndex = line.Length; } else { columnIndex--; } } while (location.LineIndex != lineIndex) { if (searchUp) { columnIndex = line.LastIndexOf(searchString, columnIndex, matchCase, wholeWord); } else { columnIndex = line.IndexOf(searchString, columnIndex, matchCase, wholeWord); } if (columnIndex >= 0) { location.ColumnIndex = columnIndex; return this.CreateStringSpan(location, length); } if (searchUp) { location.MoveUp(1); } else { location.MoveDown(1); } line = location.Line; if (searchUp) { columnIndex = line.Length; } else { columnIndex = 0; } } if (searchUp) { columnIndex = line.LastIndexOf(searchString, columnIndex, matchCase, wholeWord); if ((columnIndex != -1) && (columnIndex >= startLocation.ColumnIndex)) { location.ColumnIndex = columnIndex; return this.CreateStringSpan(location, length); } } else { columnIndex = line.IndexOf(searchString, columnIndex, matchCase, wholeWord); if ((columnIndex != -1) && ((columnIndex + length) <= endLocation.ColumnIndex)) { location.ColumnIndex = columnIndex; return this.CreateStringSpan(location, length); } } location.Dispose(); return null; }