示例#1
0
 public int Find(string findText, bool matchCase, bool searchReverse)
 {
     if (this.textView != null)
     {
         int startIndex = this.TextView.Caret.Position.Index;
         if (!this.TextView.Selection.IsEmpty)
         {
             SnapshotSpan selectionSpan1 = this.TextView.Selection.SelectionSpan;
             SnapshotSpan selectionSpan2 = this.TextView.Selection.SelectionSpan;
             if (selectionSpan2.Length > 0)
             {
                 startIndex = !searchReverse ? selectionSpan2.End : selectionSpan2.End - 1;
             }
         }
         this.findLogic.TextSnapshotToSearch = this.TextSnapshot;
         this.findLogic.MatchCase            = matchCase;
         this.findLogic.SearchString         = findText;
         this.findLogic.SearchReverse        = searchReverse;
         SnapshotSpan?next = this.findLogic.FindNext(startIndex, true);
         if (next.HasValue)
         {
             ITextEditor textEditor = (ITextEditor)this;
             textEditor.ClearSelection();
             textEditor.Select(next.Value.Start, next.Value.Length);
             textEditor.EnsureSpanVisible(next.Value.Start, next.Value.Length);
             textEditor.CaretPosition = next.Value.End;
             textEditor.EnsureCaretVisible();
             return(next.Value.Start);
         }
     }
     return(-1);
 }
示例#2
0
		public static void MoveStatementDown(ITextEditor editor)
		{
			MoveStatement(editor, MoveStatementDirection.Down);
			editor.ClearSelection();
		}
示例#3
0
        public static void GoToXaml(SceneView sceneView, SceneXamlDocument document, List <DocumentNode> targetNodes, bool selectElementNameOnly, bool setFocusToXamlEditor)
        {
            ITextRange         selectionSpan      = TextRange.Null;
            bool               flag               = false;
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(document.ProjectContext);

            if (projectXamlContext == null)
            {
                return;
            }
            DocumentNode rootNode = document.RootNode;

            if (rootNode != null && targetNodes != null)
            {
                foreach (DocumentNode documentNode in targetNodes)
                {
                    DocumentNode node = GoToXamlCommand.GetCorrespondingDocumentNode(documentNode, rootNode);
                    if (node != null)
                    {
                        ITextRange nodeSpan;
                        for (nodeSpan = DocumentNodeHelper.GetNodeSpan(node); TextRange.IsNull(nodeSpan) && node != null && node != rootNode; nodeSpan = DocumentNodeHelper.GetNodeSpan(node))
                        {
                            node = (DocumentNode)node.Parent;
                        }
                        if (!TextRange.IsNull(nodeSpan))
                        {
                            if (!flag)
                            {
                                flag          = true;
                                selectionSpan = nodeSpan;
                            }
                            else
                            {
                                selectionSpan = TextRange.Union(selectionSpan, nodeSpan);
                            }
                        }
                    }
                }
            }
            if (sceneView == null)
            {
                sceneView = projectXamlContext.OpenView((IDocumentRoot)document, true);
            }
            using (sceneView.DisableSelectionSynchronization())
            {
                sceneView.EnsureXamlEditorVisible();
                if (!flag || sceneView.CodeEditor == null)
                {
                    return;
                }
                ITextEditor textEditor = sceneView.CodeEditor;
                textEditor.ClearSelection();
                if (selectElementNameOnly)
                {
                    selectionSpan = GoToXamlCommand.GetElementNameSelectionSpan((IReadableSelectableTextBuffer)document.TextBuffer, selectionSpan);
                }
                textEditor.Select(selectionSpan.Offset, selectionSpan.Length);
                textEditor.CaretPosition = selectionSpan.Offset + selectionSpan.Length;
                Action action = (Action)(() =>
                {
                    textEditor.EnsureSpanVisible(selectionSpan.Offset, selectionSpan.Length);
                    textEditor.EnsureCaretVisible();
                    textEditor.MoveLineToCenterOfView(textEditor.GetLineNumberFromPosition(selectionSpan.Offset));
                    if (!setFocusToXamlEditor)
                    {
                        return;
                    }
                    textEditor.Focus();
                });
                if (SceneViewUpdateScheduleTask.Synchronous)
                {
                    action();
                }
                else
                {
                    UIThreadDispatcher.Instance.BeginInvoke(DispatcherPriority.Render, action);
                }
            }
        }
示例#4
0
 public void MoveStatementUp()
 {
     MoveStatement(editor, MoveStatementDirection.Up);
     editor.ClearSelection();
 }
示例#5
0
        private void OnContentRelatedActionClick(object sender, EventArgs e)
        {
            ToolStripMenuItem mnuItem = sender as ToolStripMenuItem;

            if (mnuItem == null)
            {
                return;
            }
            if (_textEditor == null)
            {
                return;
            }

            string tag = mnuItem.Tag as String;

            if (String.IsNullOrEmpty(tag))
            {
                return;
            }
            tag = tag.ToLowerInvariant();
            switch (tag)
            {
            case "getcontent":
                AddMessage("---------> [Begin TextEditor GetContent] <---------");
                AddMessage(_textEditor.Content);
                AddMessage("---------> [End TextEditor GetContent] <---------");
                break;

            case "setcontent":
                _textEditor.Content = "This is sample content from the add in!";
                break;

            case "getwordatcursor":
                AddMessage("WordAtCursor: " + _textEditor.WordAtCursor);
                break;

            case "getselectedtext":
                AddMessage("Selected Text: " + _textEditor.SelectedText);
                break;

            case "clearselection":
                _textEditor.ClearSelection();
                AddMessage("Selection cleared.");
                break;

            case "deleteselection":
                _textEditor.DeleteSelection();
                AddMessage("Selection deleted.");
                break;

            case "insertcontent":
                _textEditor.InsertContent("This is INSERTED content from addin.");
                AddMessage("Content inserted.");
                break;

            case "appendcontent":
                _textEditor.AppendContent("This is APPENDED content from addin.");
                AddMessage("Content appended.");
                break;

            default:
                AddError("UNKNOWN ACTION!");
                break;
            }
        }
示例#6
0
 public static void MoveStatementDown(ITextEditor editor)
 {
     MoveStatement(editor, MoveStatementDirection.Down);
     editor.ClearSelection();
 }