Ejemplo n.º 1
0
 public void Select(int start, int length)
 {
     start = Math.Abs(start);
     start = Math.Abs(length);
     Execute.OnUIThreadEx(() =>
     {
         if (start > textEditor.Document.TextLength)
         {
             start = textEditor.Document.TextLength - 1;
         }
         if (start + length > textEditor.Document.TextLength)
         {
             length = textEditor.Document.TextLength - start;
         }
         textEditor.Select(start, length);
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Move caret to offset.
        /// </summary>
        /// <param name="findText">Text which was finded.</param>
        /// <param name="offset">Offset where the text is.</param>
        /// <param name="scrollToCaret">If true editor will scroll to caret.</param>
        /// <returns>Returns true if the caret was moved, false otherwise.</returns>
        /// <remarks>This function will return false if the finded text need to be 'whole word' and it isn't.</remarks>
        private bool MoveCaret(string findText, int offset, bool scrollToCaret)
        {
            CodeTextEditor editor = Workspace.CurrentEditor.TextEditor;

            editor.Select(offset, findText.Length);

            // Check if we need the whole word, if we need it let's compare with the selection.
            if (this.wholeWordCheckBox.Checked == true && string.Compare(editor.SelectedText, findText) != 0)
            {
                editor.TextArea.ClearSelection();
                return(false);
            }

            if (scrollToCaret == true)
            {
                DocumentLine documentLine = editor.TextArea.Document.GetLineByOffset(offset);
                editor.ScrollTo(documentLine.LineNumber, 0);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scroll to correct line in the editor. This could be called from a DispatcherTimer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GotoDefinition_ScrollToLine(object sender = null, EventArgs e = null)
        {
            var timer = sender as DispatcherTimer;

            if (timer != null)
            {
                timer.Stop();
            }

            var args = _gotoDefinitionArgs;

            if (CodeTextEditor != null)
            {
                if (args.LineNumber != -1)
                {
                    ICSharpCode.AvalonEdit.Document.DocumentLine line = CodeTextEditor.Document.GetLineByNumber(args.LineNumber);

                    CodeTextEditor.Select(line.Offset, line.Length);
                    CodeTextEditor.CaretOffset = line.Offset;
                    CodeTextEditor.ScrollToLine(args.LineNumber);
                    CodeTextEditor.Focus();
                }
            }
        }