Skip to content

Commit c948155

Browse files
authored
diff: the focus hook answers to either name the engine stamps on its elements (#96953)
1 parent e1bb7b0 commit c948155

6 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎mods/diff/hooks/names/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export * from './command-name.js'
33
export * from './keys'
44
export * from './pane-id.js'
55
export * from './pane-title.js'
6-
export * from './plugin-name.js'
6+
export * from './plugin-names.js'
77
export * from './texts'
88

99
export * as default from '.'

‎mods/diff/hooks/names/plugin-name.ts‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The names the engine may stamp on the elements this plugin's render hooks
3+
* draw (`ui.press`, `ui.focus`): its own, and the one a build that carries
4+
* it registers it under.
5+
*/
6+
export const PLUGIN_NAMES = ['diff', 'cc-plugin-diff'] as const

‎mods/diff/hooks/register.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ export function register(on: On) {
833833
return result
834834
})
835835

836-
on('ui.focus', { plugin: Names.PLUGIN_NAME }, ($, e, next) => {
836+
on('ui.focus', { plugin: Names.PLUGIN_NAMES }, ($, e, next) => {
837837
const isListed =
838838
model.placement === 'inline' && model.dialogView === 'list' && host
839839

‎mods/diff/tests/fixtures/ring-onto.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { PANE } from './pane.js'
77
* elements, as the engine raises it before the ring moves.
88
*
99
* @param key the element's key
10+
* @param plugin the name the engine stamped on the element
1011
* @returns the `ui.focus` input
1112
*/
12-
export const ringOnto = (key: string): UiFocusInput => ({
13+
export const ringOnto = (key: string, plugin = 'diff'): UiFocusInput => ({
1314
component: 'Pane',
1415
requestId: PANE.requestId,
15-
plugin: 'diff',
16+
plugin,
1617
element: key,
1718
origin: { kind: 'person' },
1819
})

‎mods/diff/tests/views.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,24 @@ describe('views', () => {
200200
expect(walked).not.toContain('file0.ts')
201201
})
202202

203+
test('the walk follows under the name a build registers', async ($, on) => {
204+
const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
205+
206+
await $.session.start(Fixtures.SESSION)
207+
await $.command.run(Fixtures.DIALOG_DIFF)
208+
await world.clock.advance(Fixtures.SETTLE_MS)
209+
await $.ui.render(Fixtures.INLINE_PANE)
210+
211+
expect(
212+
await $.ui.focus(Fixtures.ringOnto('file:file3.ts', 'cc-plugin-diff')),
213+
).toEqual({})
214+
215+
expect(
216+
world.focused.map(focus => focus.element),
217+
'its row once centred',
218+
).toEqual(['file:file2.ts'])
219+
})
220+
203221
test('off fullscreen, the walk stops at the last file', async ($, on) => {
204222
const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
205223

0 commit comments

Comments
 (0)