spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

diff: the focus hook answers to either name the engine stamps on its elementsBrowse files
poteat authored 29 days ago parent 684ffc4 · commit e2697fdf4388
6 changed files+29 -9compared with 684ffc4
Mmods/diff/hooks/names/index.ts
Dmods/diff/hooks/names/plugin-name.ts
Amods/diff/hooks/names/plugin-names.ts
Mmods/diff/hooks/register.ts
Mmods/diff/tests/fixtures/ring-onto.ts
Mmods/diff/tests/views.test.ts
@@ -3,7 +3,7 @@
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 '.'
Dmods/diff/hooks/names/plugin-name.ts+0 -5
@@ -1,5 +1,0 @@
1-/**
2- * The plugin's own name, as the engine stamps it on the elements its render
3- * hooks draw (`ui.press`, `ui.focus`).
4- */
5-export const PLUGIN_NAME = 'diff'
@@ -1,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
@@ -833,7 +833,7 @@
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
@@ -7,12 +7,13 @@
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 })
@@ -200,6 +200,24 @@
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