@@ -47,7 +47,13 @@ This shows that using keyboardHideStart event is faster than not using it.
47
47
* @param {function } onremove Callback to call when palette is removed
48
48
* @returns {void }
49
49
*/
50
+ // Track active palette for chaining
51
+ let activePalette = null ;
52
+
50
53
export default function palette ( getList , onsSelectCb , placeholder , onremove ) {
54
+ // Store previous palette if exists
55
+ const previousPalette = activePalette ;
56
+ const isChained = ! ! previousPalette ;
51
57
/**@type {HTMLInputElement } */
52
58
const $input = (
53
59
< input
@@ -65,8 +71,11 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
65
71
// Create a palette with input and hints
66
72
inputhints ( $input , generateHints , onSelect ) ;
67
73
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
+ }
70
79
71
80
// Remove palette when input is blurred
72
81
$input . addEventListener ( "blur" , remove ) ;
@@ -77,24 +86,41 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
77
86
// Add to DOM
78
87
app . append ( $palette , $mask ) ;
79
88
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
+
80
97
// Focus input to show options
81
98
$input . focus ( ) ;
82
99
100
+ // Trigger input event to show hints immediately
101
+ $input . dispatchEvent ( new Event ( "input" ) ) ;
102
+
83
103
// Add to action stack to remove on back button
84
104
actionStack . push ( {
85
105
id : "palette" ,
86
106
action : remove ,
87
107
} ) ;
108
+ // Store this palette as the active one for chaining
109
+ activePalette = { remove } ;
88
110
89
111
/**
90
112
* On select callback for inputhints
91
113
* @param {string } value
92
114
*/
93
115
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
+ }
98
124
}
99
125
100
126
/**
@@ -113,7 +139,7 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
113
139
*/
114
140
async function generateHints ( setHints , hintModification ) {
115
141
const list = getList ( hintModification ) ;
116
- let data = list instanceof Promise ? await list : list ;
142
+ const data = list instanceof Promise ? await list : list ;
117
143
setHints ( data ) ;
118
144
}
119
145
@@ -125,18 +151,28 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) {
125
151
keyboardHandler . off ( "keyboardHideStart" , remove ) ;
126
152
$input . removeEventListener ( "blur" , remove ) ;
127
153
128
- restoreTheme ( ) ;
129
154
$palette . remove ( ) ;
130
155
$mask . remove ( ) ;
131
156
157
+ // Restore previous palette if chained
158
+ if ( isChained && previousPalette ) {
159
+ activePalette = previousPalette ;
160
+ } else {
161
+ activePalette = null ;
162
+ restoreTheme ( ) ;
163
+ }
164
+
132
165
if ( typeof onremove === "function" ) {
133
166
onremove ( ) ;
134
167
return ;
135
168
}
136
169
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
+ }
140
176
}
141
177
142
178
remove = ( ) => {
0 commit comments