11import { kPopup , pEditorToggleSave } from '@/js/consts' ;
22import { $create , $rootCL } from '@/js/dom' ;
3+ import { API } from '@/js/msg-api' ;
34import { __values } from '@/js/prefs' ;
45import { clipString , deepEqual , mapObj , sessionStore , t } from '@/js/util' ;
56import { sticky } from './compact-header' ;
@@ -72,10 +73,10 @@ const editor = self.editor = {
7273 } : editor . sections [ i ] . si ) ,
7374 } ) ,
7475
75- async save ( ) {
76+ save ( ) {
7677 if ( dirty . isDirty ( ) ) {
7778 editor . msg ||= { editorId : performance . now ( ) + Math . random ( ) } ;
78- await editor . saveImpl ( ) ;
79+ return editor . saveImpl ( ) ;
7980 }
8081 } ,
8182
@@ -94,7 +95,7 @@ const editor = self.editor = {
9495
9596 toggleStyle ( cm , enabled = ! style . enabled ) {
9697 $id ( 'enabled' ) . checked = enabled ;
97- editor . updateEnabledness ( enabled , cm && __values [ pEditorToggleSave ] ) ;
98+ editor . updateEnabledness ( enabled , cm && __values [ pEditorToggleSave ] , ! cm ) ;
9899 } ,
99100
100101 updateClass ( ) {
@@ -105,8 +106,6 @@ const editor = self.editor = {
105106 } ,
106107
107108 updateDirty ( ) {
108- if ( ! wasDirty && editor . toggling )
109- return ;
110109 const isDirty = dirty . isDirty ( ) ;
111110 if ( wasDirty !== isDirty ) {
112111 wasDirty = isDirty ;
@@ -116,14 +115,18 @@ const editor = self.editor = {
116115 editor . updateTitle ( ) ;
117116 } ,
118117
119- updateEnabledness ( enabled , autosave ) {
120- if ( autosave ) editor . toggling = true ;
121- dirty . modify ( 'enabled' , style . enabled , enabled ) ;
118+ updateEnabledness ( enabled , autosave , external ) {
119+ if ( enabled === style . enabled )
120+ return ;
121+ if ( autosave || external || style . id ) {
122+ dirty . clear ( 'enabled' ) ;
123+ } else {
124+ dirty . modify ( 'enabled' , style . enabled , enabled ) ;
125+ }
122126 style . enabled = enabled ;
123127 livePreview ( ) ;
124- if ( autosave ) {
125- editor . toggling = false ;
126- editor . save ( ) ;
128+ if ( ( ! autosave || ! editor . save ( ) ) && style . id ) {
129+ API . styles . toggle ( style . id , enabled ) ;
127130 }
128131 } ,
129132
0 commit comments