@@ -1028,11 +1028,9 @@ SBBoolean SBTextDeleteCodeUnits(SBMutableTextRef text, SBUInteger index, SBUInte
10281028 /* Remove from attribute manager */
10291029 AttributeManagerRemoveRange (& text -> attributeManager , index , length );
10301030
1031- if (succeeded ) {
1032- if (!text -> isEditing ) {
1033- /* Perform immediate analysis if not in batch editing mode */
1034- succeeded = AnalyzeDirtyParagraphs (text );
1035- }
1031+ if (!text -> isEditing ) {
1032+ /* Perform immediate analysis if not in batch editing mode */
1033+ succeeded = AnalyzeDirtyParagraphs (text );
10361034 }
10371035 }
10381036
@@ -1052,16 +1050,50 @@ SBBoolean SBTextReplaceCodeUnits(SBMutableTextRef text, SBUInteger index, SBUInt
10521050{
10531051 SBUInteger rangeEnd = index + length ;
10541052 SBBoolean isRangeValid = (rangeEnd <= text -> codeUnits .count && index <= rangeEnd );
1055- SBBoolean succeeded ;
10561053
10571054 SBAssert (text -> isMutable && isRangeValid );
10581055
1059- succeeded = SBTextDeleteCodeUnits (text , index , length );
1060- if (succeeded ) {
1061- succeeded = SBTextInsertCodeUnits (text , index , codeUnitBuffer , codeUnitCount );
1056+ if (length > 0 ) {
1057+ /* Remove code units */
1058+ ListRemoveRange (& text -> codeUnits , index , length );
1059+
1060+ /* Remove bidi types */
1061+ RemoveBidiTypes (text , index , length );
1062+
1063+ /* Update paragraph structures */
1064+ UpdateParagraphsForTextRemoval (text , index , length );
10621065 }
10631066
1064- return succeeded ;
1067+ if (codeUnitCount > 0 ) {
1068+ SBUInteger byteCount ;
1069+ void * destination ;
1070+
1071+ /* Reserve space in code units */
1072+ ListReserveRange (& text -> codeUnits , index , codeUnitCount );
1073+
1074+ byteCount = codeUnitCount * text -> codeUnits .itemSize ;
1075+ destination = ListGetPtr (& text -> codeUnits , index );
1076+ memcpy (destination , codeUnitBuffer , byteCount );
1077+
1078+ /* Insert bidi types */
1079+ InsertBidiTypes (text , index , codeUnitCount );
1080+
1081+ /* Update paragraph structures */
1082+ UpdateParagraphsForTextInsertion (text , index , codeUnitCount );
1083+ }
1084+
1085+ AttributeManagerReplaceRange (& text -> attributeManager , index , length , codeUnitCount );
1086+
1087+ if (!text -> isEditing ) {
1088+ SBBoolean needsReanalysis = (length > 0 || codeUnitCount > 0 );
1089+
1090+ if (needsReanalysis ) {
1091+ /* Perform immediate analysis if not in batch editing mode */
1092+ AnalyzeDirtyParagraphs (text );
1093+ }
1094+ }
1095+
1096+ return SBTrue ;
10651097}
10661098
10671099SBBoolean SBTextSetAttribute (SBMutableTextRef text , SBUInteger index , SBUInteger length ,
0 commit comments