From 4a90bbabc36b2059ae6dfc76eac978b60f5f045c Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 04:51:10 +0530 Subject: [PATCH 1/4] feat(api): add header button registry state --- src/lib/acode.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/acode.js b/src/lib/acode.js index e727b447b..b442f7bdd 100644 --- a/src/lib/acode.js +++ b/src/lib/acode.js @@ -98,6 +98,10 @@ class Acode { // Registered formatter implementations (populated by plugins) #formatter = []; #pluginWatchers = {}; + /** @type {Map} */ + #headerButtons = new Map(); + /** Set by main.js; called whenever the header button list changes. */ + onHeaderButtonsChange = null; /** * Clear a plugin's broken mark (so it can be retried) From 4eb9710cf90218e2aa6a88d42400b30d95e79e40 Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 04:51:17 +0530 Subject: [PATCH 2/4] feat(api): expose headerButtons module to plugins --- src/lib/acode.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/acode.js b/src/lib/acode.js index b442f7bdd..71901923f 100644 --- a/src/lib/acode.js +++ b/src/lib/acode.js @@ -442,6 +442,10 @@ class Acode { this.define("themeBuilder", ThemeBuilder); this.define("selectionMenu", selectionMenu); this.define("sidebarApps", sidebarAppsModule); + this.define("headerButtons", { + add: (options) => this.addHeaderButton(options), + remove: (id) => this.removeHeaderButton(id), + }); this.define("terminal", terminalModule); this.define("webview", webview); this.define("orientation", orientation); From 293fe16d45e3260d4bc1de4654527f694a537753 Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 04:51:27 +0530 Subject: [PATCH 3/4] feat(api): add acode.addHeaderButton / removeHeaderButton --- src/lib/acode.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/lib/acode.js b/src/lib/acode.js index 71901923f..21c3dd961 100644 --- a/src/lib/acode.js +++ b/src/lib/acode.js @@ -941,6 +941,55 @@ class Acode { return Url.join(...args); } + /** + * Add a button to the main editor header, next to the edit/run buttons. + * Register an icon first with `acode.addIcon` and pass its class name. + * @param {object} options + * @param {string} options.id Unique id (re-adding the same id replaces it) + * @param {string} [options.icon] Icon class name (`.icon.`) + * @param {string} [options.label] Accessible label + * @param {() => void} options.onclick Click handler + * @param {number} [options.order=0] Lower values appear further left + * @returns {() => void} Function that removes the button + */ + addHeaderButton({ id, icon, label, onclick, order = 0 } = {}) { + if (!id || typeof onclick !== "function") { + throw new Error("addHeaderButton requires an `id` and an `onclick`."); + } + this.removeHeaderButton(id); + const $el = ( + + ); + this.#headerButtons.set(id, { order, $el }); + this.onHeaderButtonsChange?.(); + return () => this.removeHeaderButton(id); + } + + /** + * Remove a header button added with `addHeaderButton` + * @param {string} id + */ + removeHeaderButton(id) { + const entry = this.#headerButtons.get(id); + if (!entry) return; + entry.$el.remove(); + this.#headerButtons.delete(id); + this.onHeaderButtonsChange?.(); + } + + /** Header button elements, sorted by `order`. */ + get headerButtons() { + return [...this.#headerButtons.values()] + .sort((a, b) => a.order - b.order) + .map(({ $el }) => $el); + } + /** * Adds a custom icon class that can be used with the .icon element * @param {string} className - The class name for the icon (used as .icon.className) From 0ee5533b48029072c1c7ae390425ad25676e61ba Mon Sep 17 00:00:00 2001 From: Aadin Date: Mon, 23 Nov 2026 04:51:34 +0530 Subject: [PATCH 4/4] feat(header): mount plugin header buttons left of edit/run buttons --- src/main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.js b/src/main.js index cf91423da..84aa15aa2 100644 --- a/src/main.js +++ b/src/main.js @@ -693,6 +693,20 @@ async function loadApp() { }; acode.$headerToggler = $headerToggler; + + // Plugin header buttons sit just left of the edit/run buttons. Those are + // re-inserted before the menu button on file switch, so they land after. + const placeHeaderButtons = () => { + const $anchor = + [$editMenuToggler, $runBtn].find(($el) => $el.isConnected) || + $header.lastChild; + for (const $btn of acode.headerButtons) { + if ($btn.isConnected) continue; + $header.insertBefore($btn, $anchor); + } + }; + acode.onHeaderButtonsChange = placeHeaderButtons; + placeHeaderButtons(); window.actionStack = actionStack.windowCopy(); window.editorManager = editorManager; setMainMenu(settings.value.openFileListPos);