public void SetPosition(int pos)
 {
     if (editor != null)
     {
         lastCaretPosition  = pos;
         editor.CaretOffset = pos;
         DocumentLine docLine = editor.Document.GetLineByOffset(pos);
         editor.ScrollToLine(docLine.LineNumber);
     }
 }
        /// <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();
                }
            }
        }