OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // Save and restore endOfSelection and startOfLastParagraph when
necessary | 150 // Save and restore endOfSelection and startOfLastParagraph when
necessary |
151 // since moveParagraph and movePragraphWithClones can remove nod
es. | 151 // since moveParagraph and movePragraphWithClones can remove nod
es. |
152 // FIXME: This is an inefficient way to keep selection alive bec
ause indexForVisiblePosition walks from | 152 // FIXME: This is an inefficient way to keep selection alive bec
ause indexForVisiblePosition walks from |
153 // the beginning of the document to the endOfSelection everytime
this code is executed. | 153 // the beginning of the document to the endOfSelection everytime
this code is executed. |
154 // But not using index is hard because there are so many ways we
can lose selection inside doApplyForSingleParagraph. | 154 // But not using index is hard because there are so many ways we
can lose selection inside doApplyForSingleParagraph. |
155 int indexForEndOfSelection = indexForVisiblePosition(endOfSelect
ion); | 155 int indexForEndOfSelection = indexForVisiblePosition(endOfSelect
ion); |
156 doApplyForSingleParagraph(forceCreateList, listTag, currentSelec
tion.get()); | 156 doApplyForSingleParagraph(forceCreateList, listTag, currentSelec
tion.get()); |
157 if (endOfSelection.isNull() || endOfSelection.isOrphan() || star
tOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) { | 157 if (endOfSelection.isNull() || endOfSelection.isOrphan() || star
tOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) { |
158 RefPtr<Range> lastSelectionRange = TextIterator::rangeFromLo
cationAndLength(document()->documentElement(), indexForEndOfSelection, 0, true); | 158 RefPtr<Range> lastSelectionRange = TextIterator::rangeFromLo
cationAndLength(document()->documentElement(), indexForEndOfSelection, 0, true); |
| 159 // If lastSelectionRange is null, then some contents have be
en deleted from the document. |
| 160 // This should never happen and if it did, exit early immedi
ately because we've lost the loop invariant. |
| 161 ASSERT(lastSelectionRange); |
| 162 if (!lastSelectionRange) |
| 163 return; |
159 endOfSelection = lastSelectionRange->startPosition(); | 164 endOfSelection = lastSelectionRange->startPosition(); |
160 startOfLastParagraph = startOfParagraph(endOfSelection); | 165 startOfLastParagraph = startOfParagraph(endOfSelection); |
161 } | 166 } |
162 | 167 |
163 // Fetch the start of the selection after moving the first parag
raph, | 168 // Fetch the start of the selection after moving the first parag
raph, |
164 // because moving the paragraph will invalidate the original sta
rt. | 169 // because moving the paragraph will invalidate the original sta
rt. |
165 // We'll use the new start to restore the original selection aft
er | 170 // We'll use the new start to restore the original selection aft
er |
166 // we modified all selected paragraphs. | 171 // we modified all selected paragraphs. |
167 if (startOfCurrentParagraph == startOfSelection) | 172 if (startOfCurrentParagraph == startOfSelection) |
168 startOfSelection = endingSelection().visibleStart(); | 173 startOfSelection = endingSelection().visibleStart(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 if (listElement) | 384 if (listElement) |
380 return mergeWithNeighboringLists(listElement); | 385 return mergeWithNeighboringLists(listElement); |
381 | 386 |
382 if (canMergeLists(previousList, nextList)) | 387 if (canMergeLists(previousList, nextList)) |
383 mergeIdenticalElements(previousList, nextList); | 388 mergeIdenticalElements(previousList, nextList); |
384 | 389 |
385 return listElement; | 390 return listElement; |
386 } | 391 } |
387 | 392 |
388 } | 393 } |
OLD | NEW |