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); }
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); } } }