@@ -32,8 +32,12 @@ firepad.MonacoAdapter = (function() {
3232 MonacoAdapter . prototype . onChange = function ( change ) {
3333 var pair ;
3434 if ( ! this . ignoreChanges ) {
35- pair = this . operationFromMonacoChange ( change ) ;
36- this . trigger . apply ( this , [ 'change' ] . concat ( __slice . call ( pair ) ) ) ;
35+ var offsetLength = 0
36+ change . changes . forEach ( function ( chan ) {
37+ pair = this . operationFromMonacoChange ( chan , offsetLength ) ;
38+ offsetLength = offsetLength + ( pair [ 0 ] . targetLength - pair [ 0 ] . baseLength )
39+ this . trigger . apply ( this , [ 'change' ] . concat ( __slice . call ( pair ) ) ) ;
40+ } . bind ( this ) )
3741 return this . grabDocumentState ( ) ;
3842 }
3943 } ;
@@ -55,14 +59,14 @@ firepad.MonacoAdapter = (function() {
5559 } , 0 ) ;
5660 } ;
5761
58- MonacoAdapter . prototype . operationFromMonacoChange = function ( change ) {
59- text = change . changes [ 0 ] . text ;
60- start = this . indexFromPos ( change . changes [ 0 ] . range , 'start' ) ;
61- restLength = this . lastDocLines . join ( this . monacoModel . getEOL ( ) ) . length - start ;
62- text_ins = change . changes [ 0 ] . text ;
63- rangeLen = change . changes [ 0 ] . rangeLength ;
62+ MonacoAdapter . prototype . operationFromMonacoChange = function ( change , offsetLength ) {
63+ text = change . text ;
64+ start = this . indexFromPos ( change . range , 'start' ) ;
65+ restLength = this . lastDocLines . join ( this . monacoModel . getEOL ( ) ) . length - start + offsetLength ;
66+ text_ins = change . text ;
67+ rangeLen = change . rangeLength ;
6468
65- if ( change . changes [ 0 ] . rangeLength > 0 ) {
69+ if ( change . rangeLength > 0 ) {
6670 restLength -= rangeLen ;
6771 text = this . lastDocLines . join ( this . monacoModel . getEOL ( ) )
6872 . slice ( start , start + rangeLen ) ;
@@ -77,9 +81,9 @@ firepad.MonacoAdapter = (function() {
7781 del_op_ne = new firepad . TextOperation ( ) . retain ( start ) [ "delete" ] ( text )
7882 . insert ( text_ins ) . retain ( restLength ) ;
7983
80- if ( change . changes [ 0 ] . text === "" && rangeLen > 0 ) {
84+ if ( change . text === "" && rangeLen > 0 ) {
8185 return [ delete_op , insert_op ] ;
82- } else if ( change . changes [ 0 ] . text !== "" && rangeLen > 0 ) {
86+ } else if ( change . text !== "" && rangeLen > 0 ) {
8387 return [ del_op_ne , ins_op_ne ] ;
8488 } else {
8589 return [ insert_op , delete_op ] ;
0 commit comments