private bool HandleElement() { HtmlEditorDocument document = HtmlEditorDocument.TryFromTextView(_view); if (document == null) { return(false); } var tree = document.HtmlEditorTree; int position = _view.Caret.Position.BufferPosition.Position; ElementNode tag = null; AttributeNode attr = null; tree.GetPositionElement(position, out tag, out attr); if (tag != null && (tag.EndTag != null || tag.IsSelfClosing())) { int start = tag.Start; int end = tag.End; Update(start, end); return(true); } return(false); }
protected override bool Execute(FormattingCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { HtmlEditorDocument document = HtmlEditorDocument.TryFromTextView(_view); if (document == null) { return(false); } var tree = document.HtmlEditorTree; int start = _view.Selection.Start.Position.Position; int end = _view.Selection.End.Position.Position; ElementNode tag = null; AttributeNode attr = null; tree.GetPositionElement(start, out tag, out attr); if (tag == null) { return(false); } if (attr != null) { SelectAttribute(start, end, attr, tag); } else if (tag.EndTag != null && tag.StartTag.End == start && tag.EndTag.Start == end) { Select(tag.Start, tag.OuterRange.Length); } else if (tag.Children.Count > 1 && tag.Children[0].Start == start && tag.Children.Last().End == end) { Select(tag.InnerRange.Start, tag.InnerRange.Length); } else if (tag.EndTag != null && tag.Children.Count > 1 && tag.StartTag.Start < start && tag.EndTag.End > end) { Select(tag.Children[0].Start, tag.Children.Last().End - tag.Children[0].Start); } else if (tag.EndTag != null && tag.StartTag.Start < start && tag.EndTag.End > end) { Select(tag.InnerRange.Start, tag.InnerRange.Length); } else if (tag.IsSelfClosing() && tag.Start < start && tag.End > end) { Select(tag.Start, tag.OuterRange.Length); } else if (tag.Parent != null) { Select(tag.Parent.Start, tag.Parent.OuterRange.Length); } return(true); }