@@ -199,7 +199,7 @@ define(function (require, exports, module) {
199199 * @param {Object } editor - The active Editor instance whose content should be synced to the viewer.
200200 */
201201 async function _waitForMdPreviewReady ( editor ) {
202- const expectedSrc = editor ? editor . _codeMirror . getValue ( ) : null ;
202+ const expectedSrc = editor ? editor . document . getText ( ) : null ;
203203 await awaitsFor ( ( ) => {
204204 const mdIFrame = _getMdPreviewIFrame ( ) ;
205205 if ( ! mdIFrame || mdIFrame . style . display === "none" ) { return false ; }
@@ -294,8 +294,7 @@ define(function (require, exports, module) {
294294 async function _resetFileContent ( ) {
295295 const editor = EditorManager . getActiveEditor ( ) ;
296296 if ( editor && editor . document ) {
297- const cm = editor . _codeMirror ;
298- cm . setValue ( ORIGINAL_MD_CONTENT ) ;
297+ editor . document . setText ( ORIGINAL_MD_CONTENT ) ;
299298 await awaitsForDone ( CommandManager . execute ( Commands . FILE_SAVE ) , "save after reset" ) ;
300299 await awaitsFor ( ( ) => ! editor . document . isDirty , "document to be clean after reset save" ) ;
301300 await awaitsFor ( ( ) => {
@@ -333,16 +332,14 @@ define(function (require, exports, module) {
333332
334333 // Make a small edit in CM to dirty the document
335334 const editor = EditorManager . getActiveEditor ( ) ;
336- const cm = editor . _codeMirror ;
337- const doc = editor . document ;
338- cm . replaceRange ( " " , { line : 0 , ch : 0 } ) ;
335+ editor . replaceRange ( " " , { line : 0 , ch : 0 } ) ;
339336
340- await awaitsFor ( ( ) => doc . isDirty , "document to become dirty" ) ;
337+ await awaitsFor ( ( ) => editor . document . isDirty , "document to become dirty" ) ;
341338
342339 // Dispatch Ctrl+S in the md iframe — should trigger save
343340 _dispatchKeyInMdIframe ( "s" ) ;
344341
345- await awaitsFor ( ( ) => ! doc . isDirty , "document to be saved (dirty flag cleared)" ) ;
342+ await awaitsFor ( ( ) => ! editor . document . isDirty , "document to be saved (dirty flag cleared)" ) ;
346343 } , 10000 ) ;
347344
348345 it ( "should Ctrl+Shift+F in edit mode open Find in Files" , async function ( ) {
@@ -942,15 +939,15 @@ define(function (require, exports, module) {
942939 // Ensure the CM editor is created by focusing it
943940 await awaitsFor ( ( ) => {
944941 const ed = EditorManager . getActiveEditor ( ) ;
945- return ed && ed . _codeMirror ;
946- } , "CM editor for long.md to be created" ) ;
942+ return ed && ed . document ;
943+ } , "editor for long.md to be created" ) ;
947944 await _enterReaderMode ( ) ;
948945 }
949946 } , 30000 ) ;
950947
951948 function _getCMCursorLine ( ) {
952949 const editor = EditorManager . getActiveEditor ( ) ;
953- return editor ? editor . _codeMirror . getCursor ( ) . line : - 1 ;
950+ return editor ? editor . getCursorPos ( ) . line : - 1 ;
954951 }
955952
956953 function _hasViewerHighlight ( ) {
@@ -963,7 +960,7 @@ define(function (require, exports, module) {
963960 // Wait for editor to be fully ready (masterEditor established)
964961 await awaitsFor ( ( ) => {
965962 const ed = EditorManager . getActiveEditor ( ) ;
966- return ed && ed . _codeMirror && ed . document && ed . document . _masterEditor ;
963+ return ed && ed . document && ed . document . _masterEditor ;
967964 } , "editor with masterEditor to be ready" ) ;
968965
969966 // Clear any existing highlights
@@ -975,16 +972,15 @@ define(function (require, exports, module) {
975972 // Select text in CM and dispatch highlight to iframe.
976973 // MarkdownSync sends postMessage as thers some race where the cursor isnt syncing it seems
977974 const editor = EditorManager . getActiveEditor ( ) ;
978- const cm = editor . _codeMirror ;
979- cm . setSelection ( { line : 4 , ch : 0 } , { line : 6 , ch : 0 } ) ;
980- expect ( cm . getSelection ( ) . length ) . toBeGreaterThan ( 0 ) ;
975+ editor . setSelection ( { line : 4 , ch : 0 } , { line : 6 , ch : 0 } ) ;
976+ expect ( editor . getSelectedText ( ) . length ) . toBeGreaterThan ( 0 ) ;
981977
982978 const win = _getMdIFrameWin ( ) ;
983979 win . dispatchEvent ( new MessageEvent ( "message" , {
984980 data : {
985981 type : "MDVIEWR_HIGHLIGHT_SELECTION" ,
986982 fromLine : 5 , toLine : 7 ,
987- selectedText : cm . getSelection ( )
983+ selectedText : editor . getSelectedText ( )
988984 }
989985 } ) ) ;
990986
@@ -1281,10 +1277,10 @@ define(function (require, exports, module) {
12811277 await _openMdFile ( "doc2.md" ) ;
12821278 await _enterEditMode ( ) ;
12831279
1284- const cm = EditorManager . getActiveEditor ( ) . _codeMirror ;
1285- const lastLine = cm . lastLine ( ) ;
1286- cm . replaceRange ( "\n\n[CM Link](https://cm-link-test.example.com)\n" ,
1287- { line : lastLine , ch : cm . getLine ( lastLine ) . length } ) ;
1280+ const editor = EditorManager . getActiveEditor ( ) ;
1281+ const lastLine = editor . lineCount ( ) - 1 ;
1282+ editor . replaceRange ( "\n\n[CM Link](https://cm-link-test.example.com)\n" ,
1283+ { line : lastLine , ch : editor . getLine ( lastLine ) . length } ) ;
12881284
12891285 const mdDoc = _getMdIFrameDoc ( ) ;
12901286 await awaitsFor ( ( ) => {
@@ -1297,21 +1293,21 @@ define(function (require, exports, module) {
12971293 await _openMdFile ( "doc2.md" ) ;
12981294 await _enterEditMode ( ) ;
12991295
1300- const cm = EditorManager . getActiveEditor ( ) . _codeMirror ;
1301- const val = cm . getValue ( ) ;
1296+ const editor = EditorManager . getActiveEditor ( ) ;
13021297
13031298 // Add a link
1304- cm . replaceRange ( "\n[Old Link](https://old-url.example.com)\n" ,
1305- { line : cm . lastLine ( ) , ch : cm . getLine ( cm . lastLine ( ) ) . length } ) ;
1299+ const lastLine = editor . lineCount ( ) - 1 ;
1300+ editor . replaceRange ( "\n[Old Link](https://old-url.example.com)\n" ,
1301+ { line : lastLine , ch : editor . getLine ( lastLine ) . length } ) ;
13061302
13071303 const mdDoc = _getMdIFrameDoc ( ) ;
13081304 await awaitsFor ( ( ) =>
13091305 mdDoc . querySelector ( '#viewer-content a[href="https://old-url.example.com"]' ) !== null ,
13101306 "old link to appear in viewer" ) ;
13111307
13121308 // Change the URL in CM
1313- const cmVal = cm . getValue ( ) ;
1314- cm . setValue ( cmVal . replace ( "https://old-url.example.com" , "https://new-url.example.com" ) ) ;
1309+ const cmVal = editor . document . getText ( ) ;
1310+ editor . document . setText ( cmVal . replace ( "https://old-url.example.com" , "https://new-url.example.com" ) ) ;
13151311
13161312 await awaitsFor ( ( ) =>
13171313 mdDoc . querySelector ( '#viewer-content a[href="https://new-url.example.com"]' ) !== null ,
@@ -1325,20 +1321,21 @@ define(function (require, exports, module) {
13251321 await _openMdFile ( "doc3.md" ) ;
13261322 await _enterEditMode ( ) ;
13271323
1328- const cm = EditorManager . getActiveEditor ( ) . _codeMirror ;
1324+ const editor = EditorManager . getActiveEditor ( ) ;
13291325
13301326 // Add a link
1331- cm . replaceRange ( "\n[Remove Me](https://remove-cm.example.com)\n" ,
1332- { line : cm . lastLine ( ) , ch : cm . getLine ( cm . lastLine ( ) ) . length } ) ;
1327+ const lastLine = editor . lineCount ( ) - 1 ;
1328+ editor . replaceRange ( "\n[Remove Me](https://remove-cm.example.com)\n" ,
1329+ { line : lastLine , ch : editor . getLine ( lastLine ) . length } ) ;
13331330
13341331 const mdDoc = _getMdIFrameDoc ( ) ;
13351332 await awaitsFor ( ( ) =>
13361333 mdDoc . querySelector ( '#viewer-content a[href="https://remove-cm.example.com"]' ) !== null ,
13371334 "link to appear" ) ;
13381335
13391336 // Remove the link markup — replace [text](url) with just text
1340- const cmVal = cm . getValue ( ) ;
1341- cm . setValue ( cmVal . replace ( "[Remove Me](https://remove-cm.example.com)" , "Remove Me" ) ) ;
1337+ const cmVal = editor . document . getText ( ) ;
1338+ editor . document . setText ( cmVal . replace ( "[Remove Me](https://remove-cm.example.com)" , "Remove Me" ) ) ;
13421339
13431340 await awaitsFor ( ( ) =>
13441341 mdDoc . querySelector ( '#viewer-content a[href="https://remove-cm.example.com"]' ) === null ,
@@ -1390,7 +1387,7 @@ define(function (require, exports, module) {
13901387 // Verify CM source has the edited URL
13911388 const editor = EditorManager . getActiveEditor ( ) ;
13921389 await awaitsFor ( ( ) => {
1393- const cmVal = editor . _codeMirror . getValue ( ) ;
1390+ const cmVal = editor . document . getText ( ) ;
13941391 return cmVal . includes ( "https://edited-popover.example.com" ) &&
13951392 ! cmVal . includes ( "test-link-doc2.example.com" ) ;
13961393 } , "CM source to contain edited URL and not old URL" ) ;
@@ -1434,7 +1431,7 @@ define(function (require, exports, module) {
14341431 // Verify CM source has link text but no markdown link syntax
14351432 const editor = EditorManager . getActiveEditor ( ) ;
14361433 await awaitsFor ( ( ) => {
1437- const cmVal = editor . _codeMirror . getValue ( ) ;
1434+ const cmVal = editor . document . getText ( ) ;
14381435 return cmVal . includes ( "Remove Link" ) &&
14391436 ! cmVal . includes ( "[Remove Link](https://remove-link-doc3.example.com)" ) ;
14401437 } , "CM source to have plain text without link markdown" ) ;
0 commit comments