void TypingCommand::doApply() { if (endingSelection().isNone()) return; if (m_commandType == DeleteKey) if (m_commands.isEmpty()) m_openedByBackwardDelete = true; switch (m_commandType) { case DeleteSelection: deleteSelection(m_smartDelete); return; case DeleteKey: deleteKeyPressed(m_granularity); return; case ForwardDeleteKey: forwardDeleteKeyPressed(m_granularity); return; case InsertLineBreak: insertLineBreak(); return; case InsertParagraphSeparator: insertParagraphSeparator(); return; case InsertParagraphSeparatorInQuotedContent: insertParagraphSeparatorInQuotedContent(); return; case InsertText: insertText(m_textToInsert, m_selectInsertedText); return; } ASSERT_NOT_REACHED(); }
bool Editor::handleTextEvent(TextEvent* event) { // Default event handling for Drag and Drop will be handled by DragController // so we leave the event for it. if (event->isDrop()) return false; if (event->isPaste()) { if (event->pastingFragment()) replaceSelectionWithFragment(event->pastingFragment(), false, event->shouldSmartReplace(), event->shouldMatchStyle()); else replaceSelectionWithText(event->data(), false, event->shouldSmartReplace()); return true; } String data = event->data(); if (data == "\n") { if (event->isLineBreak()) return insertLineBreak(); return insertParagraphSeparator(); } return insertTextWithoutSendingTextEvent(data, false, event); }
void TypingCommand::insertText(const String &text, bool selectInsertedText) { // FIXME: Need to implement selectInsertedText for cases where more than one insert is involved. // This requires support from insertTextRunWithoutNewlines and insertParagraphSeparator for extending // an existing selection; at the moment they can either put the caret after what's inserted or // select what's inserted, but there's no way to "extend selection" to include both an old selection // that ends just before where we want to insert text and the newly inserted text. int offset = 0; int newline; while ((newline = text.find('\n', offset)) != -1) { if (newline != offset) insertTextRunWithoutNewlines(text.substring(offset, newline - offset), false); insertParagraphSeparator(); offset = newline + 1; } if (offset == 0) insertTextRunWithoutNewlines(text, selectInsertedText); else { int length = text.length(); if (length != offset) { insertTextRunWithoutNewlines(text.substring(offset, length - offset), selectInsertedText); } } }