@@ -79,7 +79,9 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
7979 /**@const */ SHOW_ALL = NodeFilter . SHOW_ALL ,
8080 blacklistedNodes = new gui . BlacklistNamespaceNodeFilter ( [ "urn:webodf:names:cursor" , "urn:webodf:names:editinfo" ] ) ,
8181 odfTextBodyFilter = new gui . OdfTextBodyNodeFilter ( ) ,
82- defaultNodeFilter = new core . NodeFilterChain ( [ blacklistedNodes , odfTextBodyFilter ] ) ;
82+ defaultNodeFilter = new core . NodeFilterChain ( [ blacklistedNodes , odfTextBodyFilter ] ) ,
83+ /**@type {!Array.<!function():undefined> }*/
84+ pendingSignals = [ ] ;
8385
8486 /**
8587 *
@@ -890,12 +892,18 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
890892 } ;
891893
892894 /**
895+ * Emit a signal to interested subscribers. Note, signals are not emitted
896+ * until *after* the current operation has completed execution in order to
897+ * ensure operation atomicity.
898+ *
893899 * @param {!string } eventid
894900 * @param {* } args
895901 * @return {undefined }
896902 */
897903 this . emit = function ( eventid , args ) {
898- eventNotifier . emit ( eventid , args ) ;
904+ pendingSignals . push ( function ( ) {
905+ eventNotifier . emit ( eventid , args ) ;
906+ } ) ;
899907 } ;
900908
901909 /**
@@ -941,15 +949,47 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
941949 callback ( ) ;
942950 } ;
943951
952+ /**
953+ * Process steps being inserted into the document. Will emit a steps inserted signal on
954+ * behalf of the caller
955+ * @param {!{position: !number} } args
956+ * @return {undefined }
957+ */
958+ this . handleStepsInserted = function ( args ) {
959+ stepsTranslator . handleStepsInserted ( args ) ;
960+ self . emit ( ops . OdtDocument . signalStepsInserted , args ) ;
961+ } ;
962+
963+ /**
964+ * Process steps being removed from the document. Will emit a steps removed signal on
965+ * behalf of the caller
966+ * @param {!{position: !number} } args
967+ * @return {undefined }
968+ */
969+ this . handleStepsRemoved = function ( args ) {
970+ stepsTranslator . handleStepsRemoved ( args ) ;
971+ self . emit ( ops . OdtDocument . signalStepsRemoved , args ) ;
972+ } ;
973+
974+ /**
975+ * Process all signals queued up during operation execution
976+ * @return {undefined }
977+ */
978+ this . processPendingSignals = function ( ) {
979+ var signal = pendingSignals . shift ( ) ;
980+ while ( signal ) {
981+ signal ( ) ;
982+ signal = pendingSignals . shift ( ) ;
983+ }
984+ } ;
985+
944986 /**
945987 * @return {undefined }
946988 */
947989 function init ( ) {
948990 filter = new ops . TextPositionFilter ( ) ;
949991 stepUtils = new odf . StepUtils ( ) ;
950992 stepsTranslator = new ops . OdtStepsTranslator ( getRootNode , createPositionIterator , filter , 500 ) ;
951- eventNotifier . subscribe ( ops . OdtDocument . signalStepsInserted , stepsTranslator . handleStepsInserted ) ;
952- eventNotifier . subscribe ( ops . OdtDocument . signalStepsRemoved , stepsTranslator . handleStepsRemoved ) ;
953993 eventNotifier . subscribe ( ops . OdtDocument . signalOperationEnd , handleOperationExecuted ) ;
954994 eventNotifier . subscribe ( ops . OdtDocument . signalProcessingBatchEnd , core . Task . processTasks ) ;
955995 }
0 commit comments