@@ -225,7 +225,7 @@ export class VSCode extends React.Component<Props> implements Editor {
225225 provideDocumentFormattingEdits = ( model , options , token ) =>
226226 prettify (
227227 model . uri . fsPath ,
228- ( ) => model . getValue ( 1 ) ,
228+ ( ) => model . getValue ( ) ,
229229 this . getPrettierConfig ( ) ,
230230 ( ) => false ,
231231 token
@@ -298,7 +298,7 @@ export class VSCode extends React.Component<Props> implements Editor {
298298 this . sendChangeOperations ( e ) ;
299299 }
300300
301- this . handleChange ( module . shortid , module . title , model . getValue ( 1 ) ) ;
301+ this . handleChange ( module . shortid , module . title , model . getValue ( ) ) ;
302302 } catch ( err ) {
303303 if ( process . env . NODE_ENV === 'development' ) {
304304 console . error ( 'caught' , err ) ;
@@ -416,7 +416,7 @@ export class VSCode extends React.Component<Props> implements Editor {
416416 if (
417417 modulePath === this . getCurrentModuleVSCodePath ( ) &&
418418 this . currentModule . code !== undefined &&
419- activeEditor . getValue ( 1 ) !== this . currentModule . code
419+ activeEditor . getValue ( ) !== this . currentModule . code
420420 ) {
421421 // Don't send these changes over live, since these changes can also be made by someone else and
422422 // we don't want to keep singing these changes
@@ -652,13 +652,15 @@ export class VSCode extends React.Component<Props> implements Editor {
652652 ) => {
653653 const results = [ ] ;
654654 let index = 0 ;
655+ const currentEOLLength = model . getEOL ( ) . length ;
656+ let eolChanged = false ;
655657 for ( let i = 0 ; i < operation . ops . length ; i ++ ) {
656658 const op = operation . ops [ i ] ;
657659 if ( TextOperation . isRetain ( op ) ) {
658660 index += op ;
659661 } else if ( TextOperation . isInsert ( op ) ) {
660662 const { lineNumber, column } = indexToLineAndColumn (
661- model . getLinesContent ( ) || [ ] ,
663+ model . getValue ( ) . split ( / \n / ) || [ ] ,
662664 index
663665 ) ;
664666 const range = new this . monaco . Range (
@@ -667,13 +669,24 @@ export class VSCode extends React.Component<Props> implements Editor {
667669 lineNumber ,
668670 column
669671 ) ;
672+
673+ // if there's a new line
674+ if ( / \n / . test ( op ) ) {
675+ const eol = / \r \n / . test ( op ) ? 2 : 1 ;
676+ if ( eol !== currentEOLLength ) {
677+ // With this insert the EOL of the document changed on the other side. We need
678+ // to accomodate our EOL to it.
679+ eolChanged = true ;
680+ }
681+ }
682+
670683 results . push ( {
671684 range,
672685 text : op ,
673686 forceMoveMarkers : true ,
674687 } ) ;
675688 } else if ( TextOperation . isDelete ( op ) ) {
676- const lines = model . getLinesContent ( ) || [ ] ;
689+ const lines = model . getValue ( ) . split ( / \n / ) || [ ] ;
677690 const from = indexToLineAndColumn ( lines , index ) ;
678691 const to = indexToLineAndColumn ( lines , index - op ) ;
679692 results . push ( {
@@ -690,6 +703,12 @@ export class VSCode extends React.Component<Props> implements Editor {
690703 }
691704
692705 this . receivingCode = true ;
706+
707+ if ( eolChanged ) {
708+ const newEolMode = currentEOLLength === 2 ? 0 : 1 ;
709+ model . setEOL ( newEolMode ) ;
710+ }
711+
693712 if ( pushStack ) {
694713 model . pushEditOperations ( [ ] , results ) ;
695714 } else {
@@ -749,7 +768,7 @@ export class VSCode extends React.Component<Props> implements Editor {
749768
750769 if ( this . props . onChange ) {
751770 this . props . onChange (
752- model . object . textEditorModel . getValue ( 1 ) ,
771+ model . object . textEditorModel . getValue ( ) ,
753772 module . shortid
754773 ) ;
755774 }
@@ -1087,7 +1106,7 @@ export class VSCode extends React.Component<Props> implements Editor {
10871106 const activeEditor = this . editor . getActiveCodeEditor ( ) ;
10881107 if ( ! activeEditor ) return '' ;
10891108
1090- return activeEditor . getValue ( 1 ) ;
1109+ return activeEditor . getValue ( ) ;
10911110 } ;
10921111
10931112 getEditorOptions = ( ) => {
0 commit comments