+2004-04-12 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by John
+
+ Some delete and insert cleanups.
+
+ * khtml/editing/htmlediting_impl.cpp:
+ (DeleteSelectionCommandImpl::doApply): For ending position case 1,
+ the caret should be placed before the first child of the containing block,
+ not before the containing block itself. Also, add some code to handle
+ converting nbsp's back to regular spaces. This will need to be improved
+ some day to convert only nbsp's added by the editor to make rendering come out right.
+ (InputTextCommandImpl::execute):
+ (TypingCommandImpl::issueCommandForDeleteKey): Make deleting collapsible whitespace part
+ of the work of deleting a selection, rather than something that needs to be done by a
+ user of DeleteSelectionCommandImpl. This makes it impossible to leave out
+ this essential step.
+ (TypingCommandImpl::deleteKeyPressed): We can't use a possible optimization here until
+ the code to do deletions properly has been factored better. Big FIXME added.
+ * layout-tests/editing/deleting/delete-block-contents-001-expected.txt: Updated for
+ ending position case 1 behavior change.
+ * layout-tests/editing/deleting/delete-block-contents-002-expected.txt: Ditto.
+ * layout-tests/editing/deleting/delete-block-contents-003-expected.txt: Ditto.
+
2004-04-09 Ken Kocienda <kocienda@apple.com>
Reviewed by Darin
if (m_selectionToDelete.state() != KHTMLSelection::RANGE)
return;
- KHTMLSelection selection = m_selectionToDelete;
+ deleteCollapsibleWhitespace(m_selectionToDelete);
+ KHTMLSelection selection = endingSelection();
DOMPosition endingPosition;
bool adjustEndingPositionDownstream = false;
// Start is not completely selected
if (startAtStartOfBlock) {
LOG(Editing, "ending position case 1");
- endingPosition = DOMPosition(downstreamStart.node()->containingEditableBlock(), 0);
+ endingPosition = DOMPosition(downstreamStart.node()->containingEditableBlock(), 1);
adjustEndingPositionDownstream = true;
}
else if (!startCompletelySelected) {
// that will replace this some day.
if (isWS(text))
insertSpace(textNode, offset);
- else
+ else {
+ const DOMString &existingText = textNode->data();
+ if (textNode->length() >= 2 && offset >= 2 && isNBSP(existingText[offset - 1]) && !isWS(existingText[offset - 2])) {
+ // DOM looks like this:
+ // character nbsp caret
+ // As we are about to insert a non-whitespace character at the caret
+ // convert the nbsp to a regular space.
+ // EDIT FIXME: This needs to be improved some day to convert back only
+ // those nbsp's added by the editor to make rendering come out right.
+ replaceText(textNode, offset - 1, 1, " ");
+ }
insertText(textNode, offset, text);
+ }
setEndingSelection(DOMPosition(textNode, offset + text.length()));
m_charactersAdded += text.length();
}
void TypingCommandImpl::issueCommandForDeleteKey()
{
- KHTMLSelection selection = endingSelection();
- ASSERT(selection.state() != KHTMLSelection::NONE);
+ KHTMLSelection selectionToDelete = endingSelection();
+ ASSERT(selectionToDelete.state() != KHTMLSelection::NONE);
- if (selection.state() == KHTMLSelection::CARET) {
- KHTMLSelection selectionToDelete(selection.startPosition().previousCharacterPosition(), selection.startPosition());
- deleteCollapsibleWhitespace(selectionToDelete);
- }
- else { // selection.state() == KHTMLSelection::RANGE
- deleteCollapsibleWhitespace();
- }
- deleteSelection(endingSelection());
+ if (selectionToDelete.state() == KHTMLSelection::CARET)
+ selectionToDelete = KHTMLSelection(selectionToDelete.startPosition().previousCharacterPosition(), selectionToDelete.startPosition());
+ deleteSelection(selectionToDelete);
}
void TypingCommandImpl::deleteKeyPressed()
{
+// EDIT FIXME: The ifdef'ed out code below should be re-enabled.
+// In order for this to happen, the deleteCharacter case
+// needs work. Specifically, the caret-positioning code
+// and whitespace-handling code in DeleteSelectionCommandImpl::doApply()
+// needs to be factored out so it can be used again here.
+// Until that work is done, issueCommandForDeleteKey() does the
+// right thing, but less efficiently and with the cost of more
+// objects.
+ issueCommandForDeleteKey();
+#if 0
if (m_cmds.count() == 0) {
issueCommandForDeleteKey();
}
issueCommandForDeleteKey();
}
}
+#endif
}
void TypingCommandImpl::removeCommand(const EditCommand &cmd)