From dcf1c46f05d7e468a05244e99a2b0f570269f08d Mon Sep 17 00:00:00 2001 From: John Perkins Date: Thu, 28 May 2026 13:34:45 -0400 Subject: [PATCH] Restore LBOS-1046 'updatefilters' editor controller action The original LBOS-1046 commits (2019, PR #4) added an `updatefilters` editor-controller action so p2-studio's CodingCanvas could dynamically restrict the toolbox to blocks/namespaces appropriate for the active codeBit / BLE bit. The v12.2.34 upstream merge preserved the `updateFilters` IMPLEMENTATION in webapp/src/app.tsx but DROPPED the wiring in pxteditor/editorcontroller.ts, so the postMessage was silently ignored. Restore: - localtypings/pxteditor.d.ts: add `"updatefilters"` to the editor action union and `updateFilters(filters?: pxt.editor.ProjectFilters)` to the IProjectView interface. - pxteditor/editorcontroller.ts: add the `case "updatefilters"` handler that calls `projectView.updateFilters((data as any).filters)`. Verified end-to-end against the FUSE editor with `ENABLE_PXT_FILTERS = true` in p2-studio: toolbox correctly drops the ~8 codeBit-inappropriate categories (Accelerometer, RgbLed, Debug, Bits, Color, Console, Lists, Arrays) and keeps the 11 bit-appropriate ones. Co-Authored-By: Claude Opus 4.7 (1M context) --- localtypings/pxteditor.d.ts | 2 ++ pxteditor/editorcontroller.ts | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/localtypings/pxteditor.d.ts b/localtypings/pxteditor.d.ts index 59845ba17139..77b5595b934f 100644 --- a/localtypings/pxteditor.d.ts +++ b/localtypings/pxteditor.d.ts @@ -66,6 +66,7 @@ declare namespace pxt.editor { | "renderxml" | "renderbyblockid" | "setscale" + | "updatefilters" | "startactivity" | "saveproject" | "compile" @@ -1028,6 +1029,7 @@ declare namespace pxt.editor { handleExtensionRequest(request: pxt.editor.ExtensionRequest): void; fireResize(): void; + updateFilters(filters?: pxt.editor.ProjectFilters): void; updateEditorLogo(left: number, rgba?: string): number; loadBlocklyAsync(): Promise; diff --git a/pxteditor/editorcontroller.ts b/pxteditor/editorcontroller.ts index fb5f9d7c4346..55524047f6a6 100644 --- a/pxteditor/editorcontroller.ts +++ b/pxteditor/editorcontroller.ts @@ -95,6 +95,15 @@ export function bindEditorMessages(getEditorAsync: () => Promise) return Promise.resolve() .then(() => projectView.editor.setScale(zoommsg.scale)); } + case "updatefilters": return Promise.resolve() + .then(() => { + // Restored from LBOS-1046 (lost in the v12 upstream merge). + // p2-studio CodingCanvas sends { type: 'pxteditor', action: 'updatefilters', + // filters: {...} } when active bits change, so the toolbox can be restricted + // to blocks/namespaces appropriate for the connected codeBit / BLE bit. + const filters = (data as any).filters as pxt.editor.ProjectFilters; + projectView.updateFilters(filters); + }); case "stopsimulator": { const stop = data as pxt.editor.EditorMessageStopRequest; return Promise.resolve()