File tree Expand file tree Collapse file tree 1 file changed +19
-14
lines changed
Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,13 @@ export default async function openFile(file, options = {}) {
3939
4040 if ( existingFile ) {
4141 // If file is already opened and new text is provided
42- const existingText = existingFile . session . getValue ( ) ;
43- const existingCursorPos = existingFile . session . selection . getCursor ( ) ;
42+ const existingText = existingFile . session . doc . toString ( ) ?? "" ;
4443
4544 // If file is already opened
4645 existingFile . makeActive ( ) ;
4746
47+ const { editor } = editorManager ;
48+
4849 if ( onsave ) {
4950 existingFile . onsave = onsave ;
5051 }
@@ -57,20 +58,24 @@ export default async function openFile(file, options = {}) {
5758 // }
5859 // if (confirmation) {
5960 // }
60- existingFile . session . setValue ( text ) ;
61+ editor . dispatch ( {
62+ changes : {
63+ from : 0 ,
64+ to : editor . state . doc . length ,
65+ insert : String ( text ) ,
66+ } ,
67+ } ) ;
6168 }
6269
63- if (
64- cursorPos &&
65- existingCursorPos &&
66- existingCursorPos . row !== cursorPos . row &&
67- existingCursorPos . column !== cursorPos . column
68- ) {
69- existingFile . session . selection . moveCursorTo (
70- cursorPos . row ,
71- cursorPos . column ,
72- ) ;
73- }
70+ // Move cursor if requested and different
71+ try {
72+ if ( cursorPos ) {
73+ const cur = editor . getCursorPosition ( ) ;
74+ if ( cur . row !== cursorPos . row || cur . column !== cursorPos . column ) {
75+ editor . gotoLine ( cursorPos . row , cursorPos . column ) ;
76+ }
77+ }
78+ } catch ( _ ) { }
7479
7580 if ( encoding && existingFile . encoding !== encoding ) {
7681 reopenWithNewEncoding ( encoding ) ;
You can’t perform that action at this time.
0 commit comments