@@ -8,19 +8,19 @@ const ext = {
88 init ( ) {
99 const ctxMenu = LiteGraph . ContextMenu
1010 // @ts -expect-error
11- // TODO Very hacky way to modify Litegraph behaviour. Fix ctx later.
11+ // TODO Very hacky way to modify Litegraph behaviour. Fix this later.
1212 LiteGraph . ContextMenu = function ( values , options ) {
13- const ctx = new ctxMenu ( values , options )
13+ const ctx = ctxMenu . call ( this , values , options )
1414
1515 // If we are a dark menu (only used for combo boxes) then add a filter input
16- if ( options ?. className === 'dark' && values ?. length > 4 ) {
16+ if ( options ?. className === 'dark' && values ?. length > 10 ) {
1717 const filter = document . createElement ( 'input' )
1818 filter . classList . add ( 'comfy-context-menu-filter' )
1919 filter . placeholder = 'Filter list'
20- ctx . root . prepend ( filter )
20+ this . root . prepend ( filter )
2121
2222 const items = Array . from (
23- ctx . root . querySelectorAll ( '.litemenu-entry' )
23+ this . root . querySelectorAll ( '.litemenu-entry' )
2424 ) as HTMLElement [ ]
2525 let displayedItems = [ ...items ]
2626 let itemCount = displayedItems . length
@@ -61,16 +61,16 @@ const ext = {
6161 }
6262
6363 const positionList = ( ) => {
64- const rect = ctx . root . getBoundingClientRect ( )
64+ const rect = this . root . getBoundingClientRect ( )
6565
6666 // If the top is off-screen then shift the element with scaling applied
6767 if ( rect . top < 0 ) {
6868 const scale =
6969 1 -
70- ctx . root . getBoundingClientRect ( ) . height /
71- ctx . root . clientHeight
72- const shift = ( ctx . root . clientHeight * scale ) / 2
73- ctx . root . style . top = - shift + 'px'
70+ this . root . getBoundingClientRect ( ) . height /
71+ this . root . clientHeight
72+ const shift = ( this . root . clientHeight * scale ) / 2
73+ this . root . style . top = - shift + 'px'
7474 }
7575 }
7676
@@ -109,7 +109,7 @@ const ext = {
109109 selectedItem ?. click ( )
110110 break
111111 case 'Escape' :
112- ctx . close ( )
112+ this . close ( )
113113 break
114114 }
115115 } )
@@ -140,15 +140,15 @@ const ext = {
140140 let top = options . event . clientY - 10
141141
142142 const bodyRect = document . body . getBoundingClientRect ( )
143- const rootRect = ctx . root . getBoundingClientRect ( )
143+ const rootRect = this . root . getBoundingClientRect ( )
144144 if (
145145 bodyRect . height &&
146146 top > bodyRect . height - rootRect . height - 10
147147 ) {
148148 top = Math . max ( 0 , bodyRect . height - rootRect . height - 10 )
149149 }
150150
151- ctx . root . style . top = top + 'px'
151+ this . root . style . top = top + 'px'
152152 positionList ( )
153153 }
154154 } )
0 commit comments