InsertNestedListCommand.cpp [plain text]
#include "config.h"
#include "InsertNestedListCommand.h"
#include "Editing.h"
#include "HTMLLIElement.h"
#include "HTMLNames.h"
#include "InsertListCommand.h"
#include "ModifySelectionListLevel.h"
namespace WebCore {
void InsertNestedListCommand::insertUnorderedList(Document& document)
{
InsertNestedListCommand::create(document, Type::UnorderedList)->apply();
}
void InsertNestedListCommand::insertOrderedList(Document& document)
{
InsertNestedListCommand::create(document, Type::OrderedList)->apply();
}
void InsertNestedListCommand::doApply()
{
if (endingSelection().isNoneOrOrphaned() || !endingSelection().isContentRichlyEditable())
return;
if (auto enclosingItem = makeRefPtr(enclosingElementWithTag(endingSelection().visibleStart().deepEquivalent(), HTMLNames::liTag))) {
auto newListItem = HTMLLIElement::create(document());
insertNodeAfter(newListItem.copyRef(), *enclosingItem);
setEndingSelection({ Position { newListItem.ptr(), Position::PositionIsBeforeChildren }, DOWNSTREAM });
auto commandType = m_type == Type::OrderedList ? IncreaseSelectionListLevelCommand::Type::OrderedList : IncreaseSelectionListLevelCommand::Type::UnorderedList;
applyCommandToComposite(IncreaseSelectionListLevelCommand::create(document(), commandType));
return;
}
auto commandType = m_type == Type::OrderedList ? InsertListCommand::Type::OrderedList : InsertListCommand::Type::UnorderedList;
applyCommandToComposite(InsertListCommand::create(document(), commandType));
}
}