879 switch(c.command) { |
880 switch(c.command) { |
880 case QTextUndoCommand::Inserted: |
881 case QTextUndoCommand::Inserted: |
881 remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation); |
882 remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation); |
882 PMDEBUG(" erase: from %d, length %d", c.pos, c.length); |
883 PMDEBUG(" erase: from %d, length %d", c.pos, c.length); |
883 c.command = QTextUndoCommand::Removed; |
884 c.command = QTextUndoCommand::Removed; |
|
885 editPos = c.pos; |
884 break; |
886 break; |
885 case QTextUndoCommand::Removed: |
887 case QTextUndoCommand::Removed: |
886 PMDEBUG(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); |
888 PMDEBUG(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); |
887 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); |
889 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); |
888 c.command = QTextUndoCommand::Inserted; |
890 c.command = QTextUndoCommand::Inserted; |
|
891 editPos = c.pos + c.length; |
889 break; |
892 break; |
890 case QTextUndoCommand::BlockInserted: |
893 case QTextUndoCommand::BlockInserted: |
891 case QTextUndoCommand::BlockAdded: |
894 case QTextUndoCommand::BlockAdded: |
892 remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation); |
895 remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation); |
893 PMDEBUG(" blockremove: from %d", c.pos); |
896 PMDEBUG(" blockremove: from %d", c.pos); |
894 if (c.command == QTextUndoCommand::BlockInserted) |
897 if (c.command == QTextUndoCommand::BlockInserted) |
895 c.command = QTextUndoCommand::BlockRemoved; |
898 c.command = QTextUndoCommand::BlockRemoved; |
896 else |
899 else |
897 c.command = QTextUndoCommand::BlockDeleted; |
900 c.command = QTextUndoCommand::BlockDeleted; |
|
901 editPos = c.pos; |
898 break; |
902 break; |
899 case QTextUndoCommand::BlockRemoved: |
903 case QTextUndoCommand::BlockRemoved: |
900 case QTextUndoCommand::BlockDeleted: |
904 case QTextUndoCommand::BlockDeleted: |
901 PMDEBUG(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); |
905 PMDEBUG(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); |
902 insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command); |
906 insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command); |
903 resetBlockRevision += 1; |
907 resetBlockRevision += 1; |
904 if (c.command == QTextUndoCommand::BlockRemoved) |
908 if (c.command == QTextUndoCommand::BlockRemoved) |
905 c.command = QTextUndoCommand::BlockInserted; |
909 c.command = QTextUndoCommand::BlockInserted; |
906 else |
910 else |
907 c.command = QTextUndoCommand::BlockAdded; |
911 c.command = QTextUndoCommand::BlockAdded; |
|
912 editPos = c.pos + 1; |
908 break; |
913 break; |
909 case QTextUndoCommand::CharFormatChanged: { |
914 case QTextUndoCommand::CharFormatChanged: { |
910 resetBlockRevision = -1; // ## TODO |
915 resetBlockRevision = -1; // ## TODO |
911 PMDEBUG(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); |
916 PMDEBUG(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); |
912 FragmentIterator it = find(c.pos); |
917 FragmentIterator it = find(c.pos); |
913 Q_ASSERT(!it.atEnd()); |
918 Q_ASSERT(!it.atEnd()); |
914 |
919 |
915 int oldFormat = it.value()->format; |
920 int oldFormat = it.value()->format; |
916 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); |
921 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); |
917 c.format = oldFormat; |
922 c.format = oldFormat; |
|
923 editPos = c.pos + c.length; |
918 break; |
924 break; |
919 } |
925 } |
920 case QTextUndoCommand::BlockFormatChanged: { |
926 case QTextUndoCommand::BlockFormatChanged: { |
921 resetBlockRevision = -1; // ## TODO |
927 resetBlockRevision = -1; // ## TODO |
922 PMDEBUG(" blockformat: format %d pos %d", c.format, c.pos); |
928 PMDEBUG(" blockformat: format %d pos %d", c.format, c.pos); |
935 group->blockInserted(it); |
941 group->blockInserted(it); |
936 } else if (group) { |
942 } else if (group) { |
937 group->blockFormatChanged(it); |
943 group->blockFormatChanged(it); |
938 } |
944 } |
939 documentChange(it.position(), it.length()); |
945 documentChange(it.position(), it.length()); |
|
946 editPos = -1; |
940 break; |
947 break; |
941 } |
948 } |
942 case QTextUndoCommand::GroupFormatChange: { |
949 case QTextUndoCommand::GroupFormatChange: { |
943 resetBlockRevision = -1; // ## TODO |
950 resetBlockRevision = -1; // ## TODO |
944 PMDEBUG(" group format change"); |
951 PMDEBUG(" group format change"); |
945 QTextObject *object = objectForIndex(c.objectIndex); |
952 QTextObject *object = objectForIndex(c.objectIndex); |
946 int oldFormat = formats.objectFormatIndex(c.objectIndex); |
953 int oldFormat = formats.objectFormatIndex(c.objectIndex); |
947 changeObjectFormat(object, c.format); |
954 changeObjectFormat(object, c.format); |
948 c.format = oldFormat; |
955 c.format = oldFormat; |
|
956 editPos = -1; |
949 break; |
957 break; |
950 } |
958 } |
951 case QTextUndoCommand::Custom: |
959 case QTextUndoCommand::Custom: |
952 resetBlockRevision = -1; // ## TODO |
960 resetBlockRevision = -1; // ## TODO |
953 if (undo) |
961 if (undo) |
954 c.custom->undo(); |
962 c.custom->undo(); |
955 else |
963 else |
956 c.custom->redo(); |
964 c.custom->redo(); |
|
965 editPos = -1; |
957 break; |
966 break; |
958 default: |
967 default: |
959 Q_ASSERT(false); |
968 Q_ASSERT(false); |
960 } |
969 } |
961 |
970 |