Ejemplo n.º 1
0
        /// <summary>
        ///     A TextSelection extension method that select parent.
        /// </summary>
        /// <param name="selection">
        ///     The target to act on.
        /// </param>
        /// <returns>
        ///     true if it succeeds, otherwise false.
        /// </returns>
        public static bool SelectParent(this TextSelection selection)
        {
            EditorPoints ep = selection.GetEditorPoints();

            XamlNode[] nodes = _rootNode.GetSelectedNodes(ep);
            if (nodes == null || nodes == null)
            {
                return(false);
            }
            XamlNode parent = nodes[0].Parent;

            selection.SetSelection(parent.BottomPoint + 1, parent.TopPoint + 1);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     A TextSelection extension method that expand selection.
        /// </summary>
        /// <param name="selection">
        ///     The target to act on.
        /// </param>
        /// <returns>
        ///     .
        /// </returns>
        public static WiddenSelectionResult ExpandSelection(this TextSelection selection)
        {
            EditorPoints ep = selection.GetEditorPoints();

            // If nothing is selected, select the closest node.
            if (ep.IsEmpty)
            {
                selection.ResetSelection(ep);
                return(selection.SelectNode() ? WiddenSelectionResult.Success : WiddenSelectionResult.NodeSelectError);
            }
            // If a node or nodes are selected, select the parent.
            if (selection.IsNodeSelected() || selection.AreSiblingsSelected())
            {
                return(selection.SelectParent()
                           ? WiddenSelectionResult.Success
                           : WiddenSelectionResult.ParentSelectError);
            }
            return(WiddenSelectionResult.LogicError);
        }
Ejemplo n.º 3
0
        private static EditorPoints GetEditorPoints(TextSelection sel, bool handleExceptions = true)
        {
            EditorPoints ep = sel.GetEditorPoints();

            try
            {
                if (_documentText == ep.DocumentText)
                {
                    return(ep);
                }

                _documentText = ep.DocumentText;
                _rootNode     = new XamlNode(_documentText);
                return(ep);
            }
            catch
            {
                ep.RestoreSelectedText(sel);
                return(EditorPoints.GetInvalidEditorPoints());
            }
        }