public static IHTMLElement GetSelectedChildEditField(IHTMLElement parent, MarkupRange selection) { if (selection == null || !selection.Positioned) { Trace.Fail("Selection is invalid!"); return(null); } IHTMLElement element = selection.ParentElement(); if (element == null || !HTMLElementHelper.IsChildOrSameElement(parent, element)) { return(null); } do { if (InlineEditField.IsEditField(element)) { return(element); } element = element.parentElement; } while (element != null && element.sourceIndex != parent.sourceIndex); return(null); }
/// <summary> /// Expands a range to the safest outter tags that can be contained without encompassing /// text that is not currently in this range. /// </summary> /// <param name="range"></param> private void SelectOuter(MarkupRange range) { IHTMLElement parent = range.ParentElement(); MarkupRange editableRange = MarkupHelpers.GetEditableRange(parent, MarkupServices); if (editableRange == null) { return; } while (parent != null && range.MoveOutwardIfNoContent()) { parent = range.Start.CurrentScope; } if (range.Start.IsLeftOf(editableRange.Start)) { range.Start.MoveToPointer(editableRange.Start); } if (range.End.IsRightOf(editableRange.End)) { range.End.MoveToPointer(editableRange.End); } return; }
private void InsertSuggestedUrl(string matchText, GlossaryLinkItem linkItem, MarkupRange markupRange) { if (GlossarySettings.AutoLinkTermsOnlyOnce && TermAlreadyLinked(matchText, linkItem.Url)) { return; } // Make sure we're not in the title and not in a hyperlink already IHTMLElement parentElement = _blogPostHtmlEditorControl.PostTitleElement; IHTMLElement currentElement = markupRange.ParentElement(); while (currentElement != null) { if (parentElement == currentElement) { return; // in the title } if (currentElement.tagName.ToLower(CultureInfo.InvariantCulture) == "a") { return; // in an anchor } currentElement = currentElement.parentElement; } if (_linkIgnoreWord != null && matchText.ToLower(CultureInfo.CurrentCulture) == _linkIgnoreWord.ToLower(CultureInfo.CurrentCulture)) { return; } _blogPostHtmlEditorControl.InsertLink(linkItem.Url, matchText, linkItem.Title, linkItem.Rel, linkItem.OpenInNewWindow, markupRange); _blogPostHtmlEditorControl.SelectedMarkupRange.Collapse(false); }
private string GetHtmlText(out MarkupPointer blockBoundary) { MarkupRange blockRange = _blogPostHtmlEditorControl.SelectedMarkupRange.Clone(); MarkupRange textRange = blockRange.Clone(); IHTMLElement ele = blockRange.ParentElement(ElementFilters.IsBlockOrTableCellOrBodyElement); if (ele == null) { blockBoundary = null; return(String.Empty); } blockRange.MoveToElement(ele, false); blockBoundary = blockRange.Start; // Fix Bug 616152 - We want the start and end pointer to match so // we can look back from the start of the insertion point (not the end, // which would include the selection that is going to be overwritten) textRange.Collapse(true); // Fix bug WinLive 59172: Specific characters of mixed characters are broken in mail body after press the 'Enter' key // Caused by using MOVEUNIT_PREVCHAR to navigate into Unicode surrogate (32-bit) characters. We work around this by moving // only at word or block boundaries. string html = null; do { int startPos = textRange.Start.MarkupPosition; textRange.Start.MoveUnitBounded(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN, blockBoundary); if (textRange.Start.MarkupPosition == startPos) { // PREVWORDBEGIN didn't actually move us, due to no word being available. // To avoid an infinite loop, just move the text range to include the whole // block and move on. textRange.Start.MoveToPointer(blockRange.Start); break; } if (textRange.Positioned && textRange.Start.IsLeftOfOrEqualTo(textRange.End)) { html = MarkupHelpers.GetRangeTextFast(textRange); } html = html ?? string.Empty; } while (html.Length < MinLookBack && textRange.Start.IsRightOf(blockRange.Start)); if (html == null && textRange.Positioned && textRange.Start.IsLeftOfOrEqualTo(textRange.End)) { html = MarkupHelpers.GetRangeTextFast(textRange); } return(html ?? string.Empty); }
private void IgnoreSuggestedUrl(string matchText, GlossaryLinkItem linkItem, MarkupRange markupRange) { IHTMLElement parent = markupRange.ParentElement(); while (parent != null && !(parent is IHTMLAnchorElement)) { parent = parent.parentElement; } if (parent != null && matchText.ToLower(CultureInfo.CurrentCulture) == parent.innerText.ToLower(CultureInfo.CurrentCulture)) { _linkIgnoreWord = matchText; } }
private bool IsValidEmoticonInsertionPoint() { MarkupRange selection = _currentSelection.Clone(); // Check to make sure the target is not in an edit field if (InlineEditField.IsWithinEditField(selection.ParentElement())) { return(false); } // Check to make sure the target is in the body of the post selection.MoveToElement(_postBodyElement, false); if (!selection.InRange(_currentSelection)) { return(false); } return(true); }