let lastDoc ; document . addEventListener ( 'call_command' , event => { const message = JSON . parse ( event . detail ) ; let result ; try { if ( message . method === 'replaceLine' ) { const row = message . args . lineNumber ; const newText = message . args . newValue ; _ide . editorManager . $scope . editor . sharejs_doc . ace . session . replace ( new ace . Range ( row , 0 , row , Number . MAX_VALUE ) , newText ) ; } else { result = { detail : JSON . stringify ( { method : message . method , value : _ide . editorManager . $scope . editor . sharejs_doc . ace . session [ message . method ] . apply ( _ide . editorManager . $scope . editor . sharejs_doc . ace . session , [ message . args ] ) } ) } ; } } catch ( e ) { } if ( result !== null && result !== undefined ) { document . dispatchEvent ( new CustomEvent ( 'return_command' , result ) ) ; } } ) ; setInterval ( ( ) => { if ( _ide && lastDoc !== _ide . editorManager . $scope . editor . sharejs_doc . doc_id ) { lastDoc = _ide . editorManager . $scope . editor . sharejs_doc . doc_id ; _ide . editorManager . $scope . editor . sharejs_doc . ace . session . on ( "changeScrollTop" , scrollTop => { let calc = _ide . editorManager . $scope . editor . sharejs_doc . ace . session . getScreenLength ( ) * _ide . editorManager . $scope . editor . sharejs_doc . ace . renderer . lineHeight ; let percentage2 = scrollTop / calc * 100 ; document . dispatchEvent ( new CustomEvent ( 'overleaf_scroll' , { detail : percentage2 } ) ) ; } ) ; } } , 2000 ) ; document . addEventListener ( 'textarea_scroll' , event => { const percentage = event . detail ; const calc = _ide . editorManager . $scope . editor . sharejs_doc . ace . session . getScreenLength ( ) * _ide . editorManager . $scope . editor . sharejs_doc . ace . renderer . lineHeight ; const scrollTop = calc * percentage / 100 ; _ide . editorManager . $scope . editor . sharejs_doc . ace . session . setScrollTop ( scrollTop ) ; } ) ; export { } ;