diff --git a/mods/diff/hooks/names/index.ts b/mods/diff/hooks/names/index.ts index 70e4a632..7b6da9de 100644 --- a/mods/diff/hooks/names/index.ts +++ b/mods/diff/hooks/names/index.ts @@ -3,7 +3,7 @@ export * from './command-name.js' export * from './keys' export * from './pane-id.js' export * from './pane-title.js' -export * from './plugin-name.js' +export * from './plugin-names.js' export * from './texts' export * as default from '.' diff --git a/mods/diff/hooks/names/plugin-name.ts b/mods/diff/hooks/names/plugin-name.ts deleted file mode 100644 index 69f71134..00000000 --- a/mods/diff/hooks/names/plugin-name.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * The plugin's own name, as the engine stamps it on the elements its render - * hooks draw (`ui.press`, `ui.focus`). - */ -export const PLUGIN_NAME = 'diff' diff --git a/mods/diff/hooks/names/plugin-names.ts b/mods/diff/hooks/names/plugin-names.ts new file mode 100644 index 00000000..77fcae47 --- /dev/null +++ b/mods/diff/hooks/names/plugin-names.ts @@ -0,0 +1,6 @@ +/** + * The names the engine may stamp on the elements this plugin's render hooks + * draw (`ui.press`, `ui.focus`): its own, and the one a build that carries + * it registers it under. + */ +export const PLUGIN_NAMES = ['diff', 'cc-plugin-diff'] as const diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.ts index f7929d93..8eda14e7 100644 --- a/mods/diff/hooks/register.ts +++ b/mods/diff/hooks/register.ts @@ -833,7 +833,7 @@ export function register(on: On) { return result }) - on('ui.focus', { plugin: Names.PLUGIN_NAME }, ($, e, next) => { + on('ui.focus', { plugin: Names.PLUGIN_NAMES }, ($, e, next) => { const isListed = model.placement === 'inline' && model.dialogView === 'list' && host diff --git a/mods/diff/tests/fixtures/ring-onto.ts b/mods/diff/tests/fixtures/ring-onto.ts index 3871a3c4..849ca778 100644 --- a/mods/diff/tests/fixtures/ring-onto.ts +++ b/mods/diff/tests/fixtures/ring-onto.ts @@ -7,12 +7,13 @@ import { PANE } from './pane.js' * elements, as the engine raises it before the ring moves. * * @param key the element's key + * @param plugin the name the engine stamped on the element * @returns the `ui.focus` input */ -export const ringOnto = (key: string): UiFocusInput => ({ +export const ringOnto = (key: string, plugin = 'diff'): UiFocusInput => ({ component: 'Pane', requestId: PANE.requestId, - plugin: 'diff', + plugin, element: key, origin: { kind: 'person' }, }) diff --git a/mods/diff/tests/views.test.ts b/mods/diff/tests/views.test.ts index 91c8e9ff..1f1bf13d 100644 --- a/mods/diff/tests/views.test.ts +++ b/mods/diff/tests/views.test.ts @@ -200,6 +200,24 @@ describe('views', () => { expect(walked).not.toContain('file0.ts') }) + test('the walk follows under the name a build registers', async ($, on) => { + const world = Fixtures.inRepository(on, Fixtures.MANY_FILES) + + await $.session.start(Fixtures.SESSION) + await $.command.run(Fixtures.DIALOG_DIFF) + await world.clock.advance(Fixtures.SETTLE_MS) + await $.ui.render(Fixtures.INLINE_PANE) + + expect( + await $.ui.focus(Fixtures.ringOnto('file:file3.ts', 'cc-plugin-diff')), + ).toEqual({}) + + expect( + world.focused.map(focus => focus.element), + 'its row once centred', + ).toEqual(['file:file2.ts']) + }) + test('off fullscreen, the walk stops at the last file', async ($, on) => { const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)