@@ -28,6 +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 { initFold , saveFold } from "@cocalc/frontend/codemirror/util" ;
31
32
32
33
// We cache a little info about each Codemirror editor we make here,
33
34
// so we can restore it when we make the same one again. Due to
@@ -147,12 +148,17 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
147
148
148
149
useEffect ( ( ) => {
149
150
if ( frameActions . current ?. frame_id != null ) {
150
- key . current = `${ frameActions . current . frame_id } ${ id } ` ;
151
+ key . current = `${ ( actions as any ) ?. path } ${
152
+ frameActions . current . frame_id
153
+ } ${ id } `;
151
154
}
152
155
init_codemirror ( options , value ) ;
153
156
154
157
return ( ) => {
155
158
if ( cm . current != null ) {
159
+ if ( key . current != null ) {
160
+ saveFold ( cm . current , key . current ) ;
161
+ }
156
162
cm_save ( ) ;
157
163
cm_destroy ( ) ;
158
164
}
@@ -638,13 +644,6 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
638
644
options0 . extraKeys [ "Ctrl-Enter" ] = ( ) => { } ;
639
645
options0 . extraKeys [ "Alt-Enter" ] = ( ) => { } ;
640
646
options0 . extraKeys [ "Cmd-Enter" ] = ( ) => { } ;
641
- /*
642
- Disabled for now since fold state isn't preserved.
643
- if (options0.foldGutter) {
644
- options0.extraKeys["Ctrl-Q"] = cm => cm.foldCodeSelectionAware();
645
- options0.gutters = ["CodeMirror-linenumbers", "CodeMirror-foldgutter"];
646
- }
647
- */
648
647
} else {
649
648
options0 . readOnly = true ;
650
649
}
@@ -762,6 +761,17 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
762
761
if ( is_focused ) {
763
762
focus_cm ( ) ;
764
763
}
764
+
765
+ if ( key . current != null ) {
766
+ initFold ( cm . current , key . current ) ;
767
+ const save = ( ) => {
768
+ if ( cm . current != null && key . current != null ) {
769
+ saveFold ( cm . current , key . current ) ;
770
+ }
771
+ } ;
772
+ cm . current . on ( "fold" , save ) ;
773
+ cm . current . on ( "unfold" , save ) ;
774
+ }
765
775
}
766
776
767
777
function focus_cm ( ) : void {
0 commit comments