void CreateLinkCommand::doApply(EditingState* editingState) { if (endingSelection().isNone()) return; HTMLAnchorElement* anchorElement = HTMLAnchorElement::create(document()); anchorElement->setHref(AtomicString(m_url)); if (endingSelection().isRange()) { applyStyledElement(anchorElement, editingState); if (editingState->isAborted()) return; } else { insertNodeAt(anchorElement, endingSelection().start(), editingState); if (editingState->isAborted()) return; Text* textNode = Text::create(document(), m_url); appendNode(textNode, anchorElement, editingState); if (editingState->isAborted()) return; document().updateStyleAndLayoutIgnorePendingStylesheets(); setEndingSelection(createVisibleSelection( Position::inParentBeforeNode(*anchorElement), Position::inParentAfterNode(*anchorElement), TextAffinity::Downstream, endingSelection().isDirectional())); } }
void CreateLinkCommand::doApply() { if (endingSelection().isNone()) return; RefPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document()); anchorElement->setHref(m_url); if (endingSelection().isRange()) applyStyledElement(anchorElement.get()); else { insertNodeAt(anchorElement.get(), endingSelection().start()); RefPtr<Text> textNode = Text::create(document(), m_url); appendNode(textNode.get(), anchorElement.get()); setEndingSelection(VisibleSelection(positionInParentBeforeNode(anchorElement.get()), positionInParentAfterNode(anchorElement.get()), DOWNSTREAM)); } }
void CreateLinkCommand::doApply() { if (endingSelection().isNone()) return; RefPtrWillBeRawPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document()); anchorElement->setHref(AtomicString(m_url)); if (endingSelection().isRange()) { applyStyledElement(anchorElement.get()); } else { insertNodeAt(anchorElement.get(), endingSelection().start()); RefPtrWillBeRawPtr<Text> textNode = Text::create(document(), m_url); appendNode(textNode.get(), anchorElement.get()); setEndingSelection(VisibleSelection(positionInParentBeforeNode(*anchorElement), positionInParentAfterNode(*anchorElement), TextAffinity::Downstream, endingSelection().isDirectional())); } }
void CreateLinkCommand::doApply() { if (endingSelection().isNone()) return; RefPtr<HTMLAnchorElement> anchorElement = new HTMLAnchorElement(document()); anchorElement->setHref(m_url); if (endingSelection().isRange()) { pushPartiallySelectedAnchorElementsDown(); applyStyledElement(anchorElement.get()); } else { insertNodeAt(anchorElement.get(), endingSelection().start()); RefPtr<Text> textNode = new Text(document(), m_url); appendNode(textNode.get(), anchorElement.get()); setEndingSelection(Selection(positionBeforeNode(anchorElement.get()), positionAfterNode(anchorElement.get()), DOWNSTREAM)); } }