From f486d19d62f1bc33246748b14b14a9dfa617b57f Mon Sep 17 00:00:00 2001 From: Iain Merrick Date: Thu, 19 Aug 2010 17:55:56 +0100 Subject: Merge WebKit at r65615 : Initial merge by git. Change-Id: Ifbf384f4531e3b58475a662e38195c2d9152ae79 --- WebCore/editing/CompositeEditCommand.cpp | 35 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'WebCore/editing/CompositeEditCommand.cpp') diff --git a/WebCore/editing/CompositeEditCommand.cpp b/WebCore/editing/CompositeEditCommand.cpp index 5ec87d6..f50929a 100644 --- a/WebCore/editing/CompositeEditCommand.cpp +++ b/WebCore/editing/CompositeEditCommand.cpp @@ -294,24 +294,24 @@ void CompositeEditCommand::joinTextNodes(PassRefPtr text1, PassRefPtr startRange = Range::create(document(), Position(document()->documentElement(), 0), endingSelection().start()); - int startIndex = TextIterator::rangeLength(startRange.get()); - int newline; + unsigned startIndex = TextIterator::rangeLength(startRange.get()); + size_t newline; do { newline = text.find('\n', offset); if (newline != offset) { RefPtr command = InsertTextCommand::create(document()); applyCommandToComposite(command); - int substringLength = newline == -1 ? length - offset : newline - offset; + int substringLength = newline == notFound ? length - offset : newline - offset; command->input(text.substring(offset, substringLength), false); } - if (newline != -1) + if (newline != notFound) insertLineBreak(); offset = newline + 1; - } while (newline != -1 && offset != length); + } while (newline != notFound && offset != length); if (selectInsertedText) { RefPtr selectedRange = TextIterator::rangeFromLocationAndLength(document()->documentElement(), startIndex, length); @@ -489,7 +489,18 @@ void CompositeEditCommand::deleteInsignificantText(PassRefPtr textNode, un if (!textRenderer) return; - InlineTextBox* box = textRenderer->firstTextBox(); + Vector sortedTextBoxes; + size_t sortedTextBoxesPosition = 0; + + for (InlineTextBox* textBox = textRenderer->firstTextBox(); textBox; textBox = textBox->nextTextBox()) + sortedTextBoxes.append(textBox); + + // If there is mixed directionality text, the boxes can be out of order, + // (like Arabic with embedded LTR), so sort them first. + if (textRenderer->containsReversedText()) + std::sort(sortedTextBoxes.begin(), sortedTextBoxes.end(), InlineTextBox::compareByStart); + InlineTextBox* box = sortedTextBoxes.isEmpty() ? 0 : sortedTextBoxes[sortedTextBoxesPosition]; + if (!box) { // whole text node is empty removeNode(textNode); @@ -526,8 +537,12 @@ void CompositeEditCommand::deleteInsignificantText(PassRefPtr textNode, un } prevBox = box; - if (box) - box = box->nextTextBox(); + if (box) { + if (++sortedTextBoxesPosition < sortedTextBoxes.size()) + box = sortedTextBoxes[sortedTextBoxesPosition]; + else + box = 0; + } } if (!str.isNull()) { -- cgit v1.1