@@ -28,10 +28,7 @@ import { Complete, Actions as CompleteActions } from "./complete";
28
28
import { Cursors } from "./cursors" ;
29
29
import { Position } from "./insert-cell/types" ;
30
30
import { is_whitespace } from "@cocalc/util/misc" ;
31
- import {
32
- getFoldedLines ,
33
- setFoldedLines ,
34
- } from "@cocalc/frontend/codemirror/util" ;
31
+ import { initFold , saveFold } from "@cocalc/frontend/codemirror/util" ;
35
32
36
33
// We cache a little info about each Codemirror editor we make here,
37
34
// so we can restore it when we make the same one again. Due to
@@ -151,14 +148,17 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
151
148
152
149
useEffect ( ( ) => {
153
150
if ( frameActions . current ?. frame_id != null ) {
154
- key . current = `${ frameActions . current . frame_id } ${ id } ` ;
151
+ key . current = `${ ( actions as any ) ?. path } ${
152
+ frameActions . current . frame_id
153
+ } ${ id } `;
155
154
}
156
155
init_codemirror ( options , value ) ;
157
156
158
157
return ( ) => {
159
158
if ( cm . current != null ) {
160
- const foldedLines = getFoldedLines ( cm . current ) ;
161
- console . log ( { foldedLines } ) ;
159
+ if ( key . current != null ) {
160
+ saveFold ( cm . current , key . current ) ;
161
+ }
162
162
cm_save ( ) ;
163
163
cm_destroy ( ) ;
164
164
}
@@ -663,7 +663,6 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
663
663
if ( node . parentNode == null ) return ;
664
664
node . parentNode . replaceChild ( elt , node ) ;
665
665
} , options0 ) ;
666
- window . x = { cm : cm . current , getFoldedLines, setFoldedLines } ;
667
666
668
667
// We explicitly re-add all the extraKeys due to weird precedence.
669
668
cm . current . addKeyMap ( options0 . extraKeys ) ;
@@ -769,6 +768,17 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
769
768
if ( is_focused ) {
770
769
focus_cm ( ) ;
771
770
}
771
+
772
+ if ( key . current != null ) {
773
+ initFold ( cm . current , key . current ) ;
774
+ const save = ( ) => {
775
+ if ( cm . current != null && key . current != null ) {
776
+ saveFold ( cm . current , key . current ) ;
777
+ }
778
+ } ;
779
+ cm . current . on ( "fold" , save ) ;
780
+ cm . current . on ( "unfold" , save ) ;
781
+ }
772
782
}
773
783
774
784
function focus_cm ( ) : void {
0 commit comments