本文整理汇总了C#中ICSharpCode.AvalonEdit.TextEditor.ScrollToLine方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.ScrollToLine方法的具体用法?C# TextEditor.ScrollToLine怎么用?C# TextEditor.ScrollToLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.AvalonEdit.TextEditor
的用法示例。
在下文中一共展示了TextEditor.ScrollToLine方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTextInTextEditor
public void FindTextInTextEditor(TextEditor te)
{
if (tbFind.Text.Length == 0) return;
// if (cbFindUp.IsChecked == false) G.CurOffset = te.SelectionStart;
// else G.CurOffset = te.SelectionStart + te.SelectionLength;
string stext = tbFind.Text;
if (cbMatchCase.IsChecked == false) stext = stext.ToLower();
// if (cbMatchWholeWord.IsChecked == true) stext = ' ' + stext + ' ';
if (cbFindUp.IsChecked == false) //Find down
{
while (true)
{
DocumentLine dl = te.Document.GetLineByOffset(G.CurOffset);
string str = te.Document.GetText(G.CurOffset, dl.Length - (G.CurOffset - dl.Offset));
if (cbMatchCase.IsChecked == false) str = str.ToLower();
int pos;
pos = str.IndexOf(stext);
if (pos != -1)
{
}
if (cbMatchWholeWord.IsChecked == true)
if (!G.LineConsist(str.Split(' '), stext)) pos = -1;
if (pos != -1)
{
te.ScrollToLine(dl.LineNumber);
te.Select(dl.Offset + pos, stext.Length);
G.CurOffset = dl.Offset + dl.TotalLength; ;
break;
}
G.CurOffset = dl.Offset + dl.TotalLength;
if (G.CurOffset >= te.Document.TextLength) { MessageBox.Show("Reached end of document."); G.CurOffset = 0; break; }
}//for
}
else // Find up
{
while (true)
{
DocumentLine dl = te.Document.GetLineByOffset(G.CurOffset);
string str = te.Document.GetText(dl.Offset, G.CurOffset - dl.Offset);
if (cbMatchCase.IsChecked == false) str = str.ToLower();
int pos = str.IndexOf(stext);
if (pos != -1)
{
te.ScrollToLine(dl.LineNumber);
te.Select(dl.Offset + pos, stext.Length);
G.CurOffset = dl.Offset + pos;
break;
}//if
if (dl.PreviousLine != null)
G.CurOffset = dl.PreviousLine.Offset + dl.PreviousLine.Length;
else G.CurOffset = 0;
if (G.CurOffset <= 0) { MessageBox.Show("Reached begin of document."); G.CurOffset = 0; break; }
}//for
}
}//func
示例2: HighlightText
public static void HighlightText(TextEditor te, int nl)
{
DocumentLine dl = te.Document.GetLineByNumber(nl);
te.UpdateLayout();
te.Select(dl.Offset, dl.Length);
te.ScrollToLine(nl);
}
示例3: ReplaceAll
private void ReplaceAll(TextEditor editor)
{
if (this.cboReplace.Text == null)
{
MessageBox.Show("No Replace Text specified");
}
int origPos = editor.CaretOffset;
if (!this.cboLookIn.SelectedValue.ToString().Equals("Selection"))
{
//Check whether the relevant Text is already selected
if (this.cboFind.Text != null && !this.cboFind.Text.Equals(String.Empty))
{
if (this.cboFind.Text.Equals(editor.SelectedText))
{
//If it is remove the selection so the FindNext() call will simply find the currently highlighted text
editor.SelectionStart = 0;
editor.SelectionLength = 0;
}
}
}
//Replace All works over the entire document unless there was already a selection present
int minPos, maxPos;
bool restoreSelection = false;
if (editor.SelectionLength > 0 && this.IsScopeSelection)
{
restoreSelection = true;
minPos = editor.SelectionStart - 1;
maxPos = editor.SelectionStart + editor.SelectionLength;
editor.CaretOffset = Math.Max(minPos, 0);
}
else
{
minPos = -1;
maxPos = editor.Text.Length;
editor.CaretOffset = 0;
}
editor.SelectionStart = 0;
editor.SelectionLength = 0;
editor.Document.BeginUpdate();
String replace = this.cboReplace.Text;
while (this.FindNext(editor, minPos, maxPos))
{
int diff = replace.Length - editor.SelectionLength;
editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, replace);
editor.SelectionLength = replace.Length;
editor.CaretOffset = editor.SelectionStart;
maxPos += diff;
}
editor.Document.EndUpdate();
editor.CaretOffset = origPos;
editor.ScrollToLine(editor.Document.GetLineByOffset(origPos).LineNumber);
if (restoreSelection)
{
editor.Select(minPos + 1, maxPos - minPos - 1);
}
}
示例4: ScrollToLine
public static void ScrollToLine(TextEditor editor, int line)
{
var max = Math.Max(1, editor.Document.LineCount);
line = Math.Min(max, Math.Max(line, 1));
editor.ScrollToLine(line);
var offset = editor.Document.GetOffset(line, 0);
editor.CaretOffset = offset;
}
示例5: SelectSymbol
/// <summary>
/// Selects a Symbol around the current selection (if any) or caret position
/// </summary>
/// <param name="editor">Text Editor</param>
public void SelectSymbol(TextEditor editor)
{
int selStart, selLength;
if (editor.SelectionStart >= 0 && editor.SelectionLength > 0)
{
selStart = editor.SelectionStart;
selLength = editor.SelectionLength;
}
else
{
selStart = editor.CaretOffset;
selLength = 0;
}
//If there is an existing Selection and deliminators are not included
//check whether the preceding and following characters are deiliminators and if so
//alter the selection start and length appropriately to include these otherwise our
//select won't select the surrounding symbol properly
if (selStart > 0 && selLength > 0 && !this._includeDelim)
{
if (this.IsStartingDeliminator(editor.Document.GetCharAt(selStart-1)))
{
selStart--;
selLength++;
}
if (selStart + selLength < editor.Document.TextLength - 1)
{
if (this.IsEndingDeliminator(editor.Document.GetCharAt(selStart + selLength))) selLength++;
}
}
char? endDelim = null;
//Extend the selection backwards
while (selStart >= 0)
{
selStart--;
selLength++;
//Start of Document is always a Boundary
if (selStart == 0) break;
//Otherwise check if character at start of selection is a boundary
char current = editor.Document.GetCharAt(selStart);
if (this.IsStartingDeliminator(current))
{
endDelim = this.RequireMatchingDeliminator(current);
break;
}
}
if (!this._includeDelim)
{
if (selStart > 0 || this.IsStartingDeliminator(editor.Document.GetCharAt(selStart)))
{
selStart++;
selLength--;
}
}
//Extend the selection forwards
while (selStart + selLength < editor.Document.TextLength)
{
selLength++;
//End of Document is always a Boundary
if (selStart + selLength == editor.Document.TextLength) break;
//Otherwise check if character after end of selection is a boundary
char current = editor.Document.GetCharAt(selStart + selLength);
if (endDelim != null )
{
//If a matching End Deliminator is required then stop when that is reached
if (endDelim == current) break;
}
else if (this.IsEndingDeliminator(current))
{
//Otherwise stop when any End Deliminator is found
break;
}
}
if (this._includeDelim)
{
selLength++;
}
//Select the Symbol Text
editor.Select(selStart, selLength);
editor.ScrollToLine(editor.Document.GetLineByOffset(selStart).LineNumber);
}
示例6: ScrollToOffset
public static void ScrollToOffset(TextEditor editor, int offset)
{
var line = editor.Document.GetLineByOffset(offset);
if (line == null) return;
editor.ScrollToLine(line.LineNumber);
editor.CaretOffset = offset;
}