@@ -47,7 +47,13 @@ This shows that using keyboardHideStart event is faster than not using it.
4747 * @param {function } onremove Callback to call when palette is removed
4848 * @returns {void }
4949 */
50+ // Track active palette for chaining
51+ let activePalette = null ;
52+
5053export default function palette ( getList , onsSelectCb , placeholder , onremove ) {
54+ // Store previous palette if exists
55+ const previousPalette = activePalette ;
56+ const isChained = ! ! previousPalette ;
5157 /**@type {HTMLInputElement } */
5258 const $input = (
5359 < input
@@ -65,8 +71,11 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
6571 // Create a palette with input and hints
6672 inputhints ( $input , generateHints , onSelect ) ;
6773
68- // Removes the darkened color from status bar and navigation bar
69- restoreTheme ( true ) ;
74+ // Only set the darkened theme when this is not a chained palette
75+ if ( ! isChained ) {
76+ // Removes the darkened color from status bar and navigation bar
77+ restoreTheme ( true ) ;
78+ }
7079
7180 // Remove palette when input is blurred
7281 $input . addEventListener ( "blur" , remove ) ;
@@ -77,24 +86,41 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
7786 // Add to DOM
7887 app . append ( $palette , $mask ) ;
7988
89+ // If we're in a chained palette, ensure we don't lose focus
90+ if ( isChained ) {
91+ // Don't let any blur events from previous palette affect this one
92+ setTimeout ( ( ) => {
93+ $input . focus ( ) ;
94+ } , 0 ) ;
95+ }
96+
8097 // Focus input to show options
8198 $input . focus ( ) ;
8299
100+ // Trigger input event to show hints immediately
101+ $input . dispatchEvent ( new Event ( "input" ) ) ;
102+
83103 // Add to action stack to remove on back button
84104 actionStack . push ( {
85105 id : "palette" ,
86106 action : remove ,
87107 } ) ;
108+ // Store this palette as the active one for chaining
109+ activePalette = { remove } ;
88110
89111 /**
90112 * On select callback for inputhints
91113 * @param {string } value
92114 */
93115 function onSelect ( value ) {
94- remove ( ) ;
95- setTimeout ( ( ) => {
96- onsSelectCb ( value ) ;
97- } , 0 ) ;
116+ const currentPalette = { remove } ;
117+ activePalette = currentPalette ;
118+
119+ onsSelectCb ( value ) ;
120+
121+ if ( activePalette === currentPalette ) {
122+ remove ( ) ;
123+ }
98124 }
99125
100126 /**
@@ -113,7 +139,7 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
113139 */
114140 async function generateHints ( setHints , hintModification ) {
115141 const list = getList ( hintModification ) ;
116- let data = list instanceof Promise ? await list : list ;
142+ const data = list instanceof Promise ? await list : list ;
117143 setHints ( data ) ;
118144 }
119145
@@ -125,18 +151,28 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
125151 keyboardHandler . off ( "keyboardHideStart" , remove ) ;
126152 $input . removeEventListener ( "blur" , remove ) ;
127153
128- restoreTheme ( ) ;
129154 $palette . remove ( ) ;
130155 $mask . remove ( ) ;
131156
157+ // Restore previous palette if chained
158+ if ( isChained && previousPalette ) {
159+ activePalette = previousPalette ;
160+ } else {
161+ activePalette = null ;
162+ restoreTheme ( ) ;
163+ }
164+
132165 if ( typeof onremove === "function" ) {
133166 onremove ( ) ;
134167 return ;
135168 }
136169
137- const { activeFile, editor } = editorManager ;
138- if ( activeFile . wasFocused ) {
139- editor . focus ( ) ;
170+ // If not chained or last in chain, focus the editor
171+ if ( ! isChained ) {
172+ const { activeFile, editor } = editorManager ;
173+ if ( activeFile . wasFocused ) {
174+ editor . focus ( ) ;
175+ }
140176 }
141177
142178 remove = ( ) => {
0 commit comments