@@ -33,41 +33,45 @@ export default class AutoResizeNodeCanvasExtension extends CanvasExtension {
3333 } ) as CanvasNode [ ]
3434 if ( selectedNodes . length === 0 ) return
3535
36- const hasLockedHeight = selectedNodes . some ( node => node . getData ( ) . lockedHeight )
36+ const autoResizeHeightEnabled = selectedNodes . some ( node => node . getData ( ) . autoResizeHeight )
3737
3838 CanvasHelper . addPopupMenuOption (
3939 canvas ,
4040 CanvasHelper . createPopupMenuOption ( {
41- id : 'lock -height' ,
42- label : 'Toggle locked height ',
43- icon : hasLockedHeight ? 'ruler ' : 'pencil-ruler ' ,
44- callback : ( ) => this . setLockedHeight ( canvas , selectedNodes , hasLockedHeight )
41+ id : 'auto-resize -height' ,
42+ label : autoResizeHeightEnabled ? 'Disable auto-resize' : 'Enable auto-resize ',
43+ icon : autoResizeHeightEnabled ? 'scan-text ' : 'lock ' ,
44+ callback : ( ) => this . toggleAutoResizeHeightEnabled ( canvas , selectedNodes , autoResizeHeightEnabled )
4545 } )
4646 )
4747 }
4848
49- private setLockedHeight ( canvas : Canvas , nodes : CanvasNode [ ] , lockedHeight : boolean ) {
50- const newLockedHeight = lockedHeight ? undefined : true
49+ private toggleAutoResizeHeightEnabled ( canvas : Canvas , nodes : CanvasNode [ ] , autoResizeHeight : boolean ) {
50+ const newAutoResizeHeight = autoResizeHeight ? undefined : true
5151
5252 nodes . forEach ( node => node . setData ( {
5353 ...node . getData ( ) ,
54- lockedHeight : newLockedHeight
54+ autoResizeHeight : newAutoResizeHeight
5555 } ) )
5656
5757 this . onPopupMenuCreated ( canvas )
5858 }
5959
60+ private canBeResized ( node : CanvasNode ) {
61+ const nodeData = node . getData ( )
62+ return nodeData . autoResizeHeight
63+ }
64+
6065 private async onNodeEditingStateChanged ( _canvas : Canvas , node : CanvasNode , editing : boolean ) {
66+ if ( ! this . canBeResized ( node ) ) return
67+
6168 await sleep ( 10 )
6269
6370 if ( editing ) {
6471 this . onNodeTextContentChanged ( _canvas , node , node . child . editMode . cm . dom )
6572 return
6673 }
6774
68- const nodeData = node . getData ( )
69- if ( nodeData . lockedHeight ) return
70-
7175 const renderedMarkdownContainer = node . nodeEl . querySelector ( ".markdown-preview-view.markdown-rendered" ) as HTMLElement | null
7276 if ( ! renderedMarkdownContainer ) return
7377
@@ -79,8 +83,7 @@ export default class AutoResizeNodeCanvasExtension extends CanvasExtension {
7983 }
8084
8185 private async onNodeTextContentChanged ( _canvas : Canvas , node : CanvasNode , dom : HTMLElement ) {
82- const nodeData = node . getData ( )
83- if ( nodeData . lockedHeight ) return
86+ if ( ! this . canBeResized ( node ) ) return
8487
8588 const cmScroller = dom . querySelector ( ".cm-scroller" ) as HTMLElement | null
8689 if ( ! cmScroller ) return
@@ -94,6 +97,10 @@ export default class AutoResizeNodeCanvasExtension extends CanvasExtension {
9497
9598 private setNodeHeight ( node : CanvasNode , height : number ) {
9699 if ( height === 0 ) return
100+
101+ // Limit the height to the maximum allowed
102+ const maxHeight = this . plugin . settings . getSetting ( 'autoResizeNodeMaxHeight' )
103+ if ( maxHeight != - 1 && height > maxHeight ) height = maxHeight
97104
98105 const nodeData = node . getData ( )
99106
0 commit comments