@@ -51,10 +51,14 @@ internal extension ParagraphTextStorage {
51
51
// then this is actually an exception from the rule that 'edited index will always be the first one'
52
52
// and in this case the LAST index should be notified as 'edited index'
53
53
if insertionLocation == baseParagraphRange. location && removedRange == baseParagraphRange && baseParagraphRange. max > 0 {
54
- if insertionRange. location == baseParagraphRange. location && difference. insertions. count > 1 ||
55
- removedRange. location == baseParagraphRange. location && difference. removals. count > 1 {
56
- lastIndexEdited = true
57
- break
54
+ if insertionRange. location == baseParagraphRange. location && difference. insertions. count > 1 ||
55
+ removedRange. location == baseParagraphRange. location && difference. removals. count > 1 {
56
+ // except the case when the whole text storage content has been deleted...
57
+ // ... like when the user selects all the text and hits 'Delete'
58
+ if removedRange. max > 0 && insertionRange. max == 0 { } else {
59
+ lastIndexEdited = true
60
+ break
61
+ }
58
62
}
59
63
}
60
64
@@ -94,9 +98,10 @@ internal extension ParagraphTextStorage {
94
98
if lastIndexEdited && difference. removals. first == change && difference. insertions. count > difference. removals. count ||
95
99
lastIndexEdited && difference. removals. last == change && difference. removals. count > difference. insertions. count {
96
100
if difference. removals. count > difference. insertions. count,
97
- let firstInsertion = difference. insertions. first, let lastTouched = difference. removals. last,
98
- case CollectionDifference < NSRange > . Change . insert( offset: _, element: let range, associatedWith: _) = firstInsertion,
99
- case CollectionDifference < NSRange > . Change . remove( offset: _, element: let touchedRange, associatedWith: _) = lastTouched {
101
+ let firstInsertion = difference. insertions. first,
102
+ let lastTouched = difference. removals. last,
103
+ case CollectionDifference < NSRange > . Change . insert( offset: _, element: let range, associatedWith: _) = firstInsertion,
104
+ case CollectionDifference < NSRange > . Change . remove( offset: _, element: let touchedRange, associatedWith: _) = lastTouched {
100
105
if touchedRange. length != range. length {
101
106
changes. append ( . editedParagraph( index: paragraphIndex, range: range) )
102
107
}
0 commit comments