@@ -199,16 +199,38 @@ export class Outline extends Model {
199199 } ,
200200 rightClick : ( element : HTMLElement , event : MouseEvent ) => {
201201 this . showContextMenu ( element , event ) ;
202+ } ,
203+ toggleClick :( liElement ) => {
204+ if ( ! liElement . nextElementSibling ) {
205+ return ;
206+ }
207+ const svgElement = liElement . firstElementChild . firstElementChild ;
208+ if ( svgElement . classList . contains ( "b3-list-item__arrow--open" ) ) {
209+ svgElement . classList . remove ( "b3-list-item__arrow--open" ) ;
210+ liElement . nextElementSibling . classList . add ( "fn__none" ) ;
211+ if ( liElement . nextElementSibling . nextElementSibling && liElement . nextElementSibling . nextElementSibling . tagName === "UL" ) {
212+ liElement . nextElementSibling . nextElementSibling . classList . add ( "fn__none" ) ;
213+ }
214+ } else {
215+ svgElement . classList . add ( "b3-list-item__arrow--open" ) ;
216+ liElement . nextElementSibling . classList . remove ( "fn__none" ) ;
217+ if ( liElement . nextElementSibling . nextElementSibling && liElement . nextElementSibling . nextElementSibling . tagName === "UL" ) {
218+ liElement . nextElementSibling . nextElementSibling . classList . remove ( "fn__none" ) ;
219+ }
220+ }
221+ this . saveExpendIds ( ) ;
202222 }
203223 } ) ;
204224 // 为了快捷键的 dispatch
205225 options . tab . panelElement . querySelector ( '[data-type="collapse"]' ) . addEventListener ( "click" , ( ) => {
206226 this . tree . collapseAll ( ) ;
227+ this . saveExpendIds ( ) ;
207228 } ) ;
208229
209230 // 普通的全部展开按钮
210231 options . tab . panelElement . querySelector ( '[data-type="expand"]' ) . addEventListener ( "click" , ( ) => {
211232 this . tree . expandAll ( ) ;
233+ this . saveExpendIds ( ) ;
212234 } ) ;
213235
214236 // 保持当前标题展开功能
@@ -591,6 +613,7 @@ export class Outline extends Model {
591613 ulElement . previousElementSibling . querySelector ( ".b3-list-item__arrow" ) . classList . add ( "b3-list-item__arrow--open" ) ;
592614 ulElement = ulElement . parentElement ;
593615 }
616+ this . saveExpendIds ( ) ;
594617 } else {
595618 while ( currentElement && currentElement . clientHeight === 0 ) {
596619 currentElement = currentElement . parentElement . previousElementSibling as HTMLElement ;
@@ -609,25 +632,22 @@ export class Outline extends Model {
609632 if ( currentElement ) {
610633 currentId = currentElement . getAttribute ( "data-node-id" ) ;
611634 }
635+ const scrollTop = this . element . scrollTop ;
612636
613637 // 保存当前文档的折叠状态到新的持久化存储
614- if ( ! this . isPreview ) {
615- const currentExpandIds = this . tree . getExpandIds ( ) ;
616- fetchPost ( "/api/storage/setOutlineStorage" , {
617- docID : this . blockId ,
618- val : {
619- expandIds : currentExpandIds
620- }
621- } ) ;
622- }
638+ this . saveExpendIds ( ) ;
623639
624640 if ( typeof callbackId !== "undefined" ) {
625641 this . blockId = callbackId ;
626642 }
627643 this . tree . updateData ( data . data ) ;
628644
629- // 从新的持久化存储恢复折叠状态
630- if ( ! this . isPreview ) {
645+ if ( this . isPreview ) {
646+ this . tree . element . querySelectorAll ( ".popover__block" ) . forEach ( item => {
647+ item . classList . remove ( "popover__block" ) ;
648+ } ) ;
649+ this . element . scrollTop = scrollTop ;
650+ } else {
631651 fetchPost ( "/api/storage/getOutlineStorage" , {
632652 docID : this . blockId
633653 } , storageResponse => {
@@ -640,15 +660,9 @@ export class Outline extends Model {
640660 if ( ( this . headerElement . querySelector ( "input.b3-text-field.search__label" ) as HTMLInputElement ) . value ) {
641661 this . setFilter ( ) ;
642662 }
663+ this . element . scrollTop = scrollTop ;
643664 } ) ;
644665 }
645-
646- if ( this . isPreview ) {
647- this . tree . element . querySelectorAll ( ".popover__block" ) . forEach ( item => {
648- item . classList . remove ( "popover__block" ) ;
649- } ) ;
650- }
651-
652666 if ( currentId ) {
653667 currentElement = this . element . querySelector ( `[data-node-id="${ currentId } "]` ) ;
654668 if ( currentElement ) {
@@ -782,6 +796,7 @@ export class Outline extends Model {
782796 }
783797 } ) ;
784798 }
799+ this . saveExpendIds ( ) ;
785800 }
786801
787802 /**
@@ -833,6 +848,7 @@ export class Outline extends Model {
833848 }
834849 }
835850 } ) ;
851+ this . saveExpendIds ( ) ;
836852 }
837853
838854 private collapseChildren ( element : HTMLElement , expand ?: boolean ) {
@@ -855,6 +871,7 @@ export class Outline extends Model {
855871 arrowElement . classList . remove ( "b3-list-item__arrow--open" ) ;
856872 nextElement . classList . add ( "fn__none" ) ;
857873 }
874+ this . saveExpendIds ( ) ;
858875 }
859876
860877 /**
@@ -1152,14 +1169,18 @@ export class Outline extends Model {
11521169 label : window . siyuan . languages . expandAll ,
11531170 click : ( ) => {
11541171 this . tree . expandAll ( ) ;
1172+ this . saveExpendIds ( ) ;
11551173 }
11561174 } ) . element ) ;
11571175
11581176 // 全部折叠
11591177 window . siyuan . menus . menu . append ( new MenuItem ( {
11601178 icon : "iconContract" ,
11611179 label : window . siyuan . languages . foldAll ,
1162- click : ( ) => this . tree . collapseAll ( )
1180+ click : ( ) => {
1181+ this . tree . collapseAll ( ) ;
1182+ this . saveExpendIds ( ) ;
1183+ }
11631184 } ) . element ) ;
11641185
11651186 window . siyuan . menus . menu . popup ( {
0 commit comments