diff --git a/src/static/js/pad_editbar.ts b/src/static/js/pad_editbar.ts index cb8dae2a781..0f4a5b0ef22 100644 --- a/src/static/js/pad_editbar.ts +++ b/src/static/js/pad_editbar.ts @@ -144,6 +144,21 @@ exports.padeditbar = new class { this._bodyKeyEvent(evt); }); + // After any toolbar-select change (e.g. ep_headings style picker, + // ep_font_size), return keyboard focus to the pad editor so the caret + // is back at its previous location. Plugin-provided is hidden behind the + // nice-select wrapper, which on option click does `val(x).trigger('change')` + // internally (see src/static/js/vendors/nice-select.ts). Replicate that + // directly rather than trying to click through the wrapper UI. + await hs.evaluate((el: HTMLSelectElement) => { + el.value = '0'; + el.dispatchEvent(new Event('change', {bubbles: true})); + }); + + // After the change, keyboard input should go into the pad, not the + // toolbar. Write a marker and verify both chunks appear in the pad. + await page.keyboard.type('after'); + await page.waitForTimeout(200); + const bodyText = await padBody.innerText(); + expect(bodyText).toContain('before'); + expect(bodyText).toContain('after'); +});