ScrollToLine() public method

Scrolls to the specified line. This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
public ScrollToLine ( int line ) : void
line int
return void
Ejemplo n.º 1
0
        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
Ejemplo n.º 2
0
        private void AddFileView(FileItem file_item, VertexControl source, PocVertex source_vertex, List <int> lines = null)
        {
            if (!graph_provider.root_vertex.CtagsRun)
            {
                System.Windows.Forms.MessageBox.Show("Ctags is still running, so tags are not available.", "Ctags running", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            FileVertex    new_vertex         = graph_provider.AddFileView(file_item, source_vertex);
            VertexControl new_vertex_control = new VertexControl(new_vertex)
            {
                DataContext = new_vertex
            };

            try
            {
                graph_area.AddVertex(new_vertex, new_vertex_control);
            }
            catch (GraphX.GX_InvalidDataException)
            {
                new_vertex_control = graph_area.GetAllVertexControls().Where(c => c.Vertex == new_vertex).First();
            }

            PocEdge new_edge = new PocEdge(source_vertex, new_vertex);

            graph_area.InsertEdge(new_edge, new EdgeControl(source, new_vertex_control, new_edge));
            graph_area.RelayoutGraph(true);
            graph_area.UpdateLayout();
            centre_on_me = new_vertex_control;
            ICSharpCode.AvalonEdit.TextEditor editor = TreeHelpers.FindVisualChild <ICSharpCode.AvalonEdit.TextEditor>(new_vertex_control);
            if (editor != null && editor != NotesEditor)
            {
                editor.TextArea.TextView.MouseDown += TestEditor_MouseDown;
                editor.TextArea.SelectionChanged   += TestEditor_SelectionChanged;
                if (graph_provider.root_vertex.CtagsRun)
                {
                    editor.TextArea.TextView.LineTransformers.Add(new UnderlineCtagsMatches(graph_provider.root_vertex.CtagsMatches.Keys.ToList()));
                }
                if (lines != null)
                {
                    editor.TextArea.TextView.BackgroundRenderers.Add(new HighlightSearchLineBackgroundRenderer(editor, lines));
                    editor.ScrollToLine(lines.Min());
                }
                editor.Width = editor.ActualWidth;
            }
        }
Ejemplo n.º 3
0
        private void MoveCaretToSource(SegmentLocation loc, ICSharpCode.AvalonEdit.TextEditor editor, bool selectText = true, int?tabToSelect = null)
        {
            if (loc != null)
            {
                var start = loc.Start.Offset;
                var end   = loc.End.Offset;
                editor.ScrollToLine(editor.Document.GetLocation(start).Line);

                if (selectText)
                {
                    editor.Select(start, end - start + 1);
                }

                if (tabToSelect.HasValue)
                {
                    MainTabs.SelectedIndex = tabToSelect.Value;
                }
            }
            else
            {
                editor.Select(0, 0);
            }
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 public void ScrollToLine(int line)
 {
     _editor.ScrollToLine(line);
 }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
 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;
 }