From f2ef303de62b5f12e32aa1329f5a213719bfd81c Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 15 May 2026 18:53:12 +0100 Subject: [PATCH] =?UTF-8?q?feat(toolbarSelect):=20DRY=20up=20`-change → ace edit → focus-restore boilerplate that plugins like `ep_font_color`, `ep_font_size`, and `ep_headings2` each implement by hand: + +```js +// before — repeated in each plugin +exports.postAceInit = (hookName, context) => { + const hs = $('#font-size, select.size-selection'); + hs.on('change', function () { + const value = $(this).val(); + const intValue = parseInt(value, 10); + if (!isNaN(intValue)) { + context.ace.callWithAce((ace) => { + ace.ace_doInsertsizes(intValue); + }, 'insertsize', true); + hs.val('dummy'); + context.ace.focus(); + } + }); +}; +``` + +With this helper: + +```js +// Client-only — import the sub-path directly so esbuild doesn't pull +// any server-only deps into the pad bundle. +const {toolbarSelect} = require('ep_plugin_helpers/toolbar-select'); + +exports.postAceInit = (hookName, context) => { + toolbarSelect({ + selector: '#font-size, select.size-selection', + context, + invoke: (ace, value) => ace.ace_doInsertsizes(value), + op: 'insertsize', + }); +}; +``` + +**Config:** + +| Field | Required | Default | Description | +|-------|----------|---------|-------------| +| `selector` | yes | — | jQuery selector for the toolbar ` dropdown that triggers an ace edit operation, then restores +// focus to the editor so the user can keep typing without an extra click. +// +// Centralises the three-step boilerplate that ep_font_color, ep_font_size, +// ep_headings2 and similar plugins repeat by hand: +// +// 1. on change → coerce the picked value +// 2. wrap the edit in callWithAce(...) so it joins the undo stack +// 3. reset the