From f86a6a6571611e1c265f8f9d1811e199037de254 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Fri, 21 Mar 2025 10:47:28 +0530 Subject: [PATCH 1/2] fix: palette chaining with compatibility --- src/components/palette/index.js | 58 +++++++++++++++++++++++++------ src/palettes/changeTheme/index.js | 2 -- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/components/palette/index.js b/src/components/palette/index.js index 09f1dd74..899a26cd 100644 --- a/src/components/palette/index.js +++ b/src/components/palette/index.js @@ -47,7 +47,13 @@ This shows that using keyboardHideStart event is faster than not using it. * @param {function} onremove Callback to call when palette is removed * @returns {void} */ +// Track active palette for chaining +let activePalette = null; + export default function palette(getList, onsSelectCb, placeholder, onremove) { + // Store previous palette if exists + const previousPalette = activePalette; + const isChained = !!previousPalette; /**@type {HTMLInputElement} */ const $input = ( { + $input.focus(); + }, 0); + } + // Focus input to show options $input.focus(); + // Trigger input event to show hints immediately + $input.dispatchEvent(new Event("input")); + // Add to action stack to remove on back button actionStack.push({ id: "palette", action: remove, }); + // Store this palette as the active one for chaining + activePalette = { remove }; /** * On select callback for inputhints * @param {string} value */ function onSelect(value) { - remove(); - setTimeout(() => { - onsSelectCb(value); - }, 0); + const currentPalette = { remove }; + activePalette = currentPalette; + + onsSelectCb(value); + + if (activePalette === currentPalette) { + remove(); + } } /** @@ -113,7 +139,7 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) { */ async function generateHints(setHints, hintModification) { const list = getList(hintModification); - let data = list instanceof Promise ? await list : list; + const data = list instanceof Promise ? await list : list; setHints(data); } @@ -125,18 +151,28 @@ export default function palette(getList, onsSelectCb, placeholder, onremove) { keyboardHandler.off("keyboardHideStart", remove); $input.removeEventListener("blur", remove); - restoreTheme(); $palette.remove(); $mask.remove(); + // Restore previous palette if chained + if (isChained && previousPalette) { + activePalette = previousPalette; + } else { + activePalette = null; + restoreTheme(); + } + if (typeof onremove === "function") { onremove(); return; } - const { activeFile, editor } = editorManager; - if (activeFile.wasFocused) { - editor.focus(); + // If not chained or last in chain, focus the editor + if (!isChained) { + const { activeFile, editor } = editorManager; + if (activeFile.wasFocused) { + editor.focus(); + } } remove = () => { diff --git a/src/palettes/changeTheme/index.js b/src/palettes/changeTheme/index.js index bf392f35..8e4ff873 100644 --- a/src/palettes/changeTheme/index.js +++ b/src/palettes/changeTheme/index.js @@ -8,8 +8,6 @@ export default function changeTheme(type = "editor") { () => generateHints(type), (value) => onselect(value), strings[type === "editor" ? "editor theme" : "app theme"], - undefined, - (value) => onselect(value), ); } From 012488e731ebc5b28c7064e2c02888b51b9c2821 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Fri, 21 Mar 2025 11:20:50 +0530 Subject: [PATCH 2/2] feat: update install button when plugin is installed --- src/sidebarApps/extensions/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sidebarApps/extensions/index.js b/src/sidebarApps/extensions/index.js index 4a2e3124..7674f2d8 100644 --- a/src/sidebarApps/extensions/index.js +++ b/src/sidebarApps/extensions/index.js @@ -455,8 +455,20 @@ function ListItem({ icon, name, id, version, downloads, installed, source }) { const { default: installPlugin } = await import("lib/installPlugin"); await installPlugin(id, remotePlugin.name, purchaseToken); + const searchInput = container.querySelector('input[name="search-ext"]'); + if (searchInput) { + searchInput.value = ""; + $searchResult.content = ""; + updateHeight($searchResult); + $installed.expand(); + } window.toast(strings["success"], 3000); - $explore.ontoggle(); + if (!$explore.collapsed) { + $explore.ontoggle(); + } + if (!$installed.collapsed) { + $installed.ontoggle(); + } } catch (err) { console.error(err); window.toast(helpers.errorMessage(err), 3000); @@ -521,6 +533,13 @@ async function uninstall(id) { ]); acode.unmountPlugin(id); + const searchInput = container.querySelector('input[name="search-ext"]'); + if (searchInput) { + searchInput.value = ""; + $searchResult.content = ""; + updateHeight($searchResult); + } + // Show Ad If Its Free Version, interstitial Ad(iad) is loaded. if (IS_FREE_VERSION && (await window.iad?.isLoaded())) { window.iad.show();