Skip to content

Commit f858930

Browse files
committed
Show snippet actions beside the selected code
1 parent b1eaa6e commit f858930

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎docs/implementation/read-only-review.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ Single-click submission follow-up: a held `/api/action` browser request reproduc
8080
Answer scrolling: when an asynchronous answer or failure arrives, Conversation follows the bottom if the reader was already within 32 pixels of it. Scrolling up keeps the current position through polling updates. Only the conversation list scrolls; the code pane and composer stay in place. Browser regressions cover both arrival at the bottom and arrival while reading earlier messages; the bottom-follow test failed before the fix with a 1,302-pixel gap.
8181

8282
Conversation width: drag the divider on its left edge to resize between 280 and 480 pixels. Focus the divider and use Left/Right for 20-pixel steps or Home/End for the limits. The width survives collapsing/reopening the pane within the page; reloading uses the layout default. This replaces the hard-to-discover native corner resize grip. The browser regression covers pointer dragging, keyboard limits, code-pane space, and collapse/reopen.
83+
84+
Selection actions now appear in a bordered floating toolbar beside the visible selected lines, with Ask emphasized. The toolbar stays within the code viewport, leaves line numbers available for Shift-click extension, and hides when the selection scrolls out of view. Clear selection removes it. The long-diff browser regression checks proximity, viewport bounds, attachment, scrolling away/back, and clearing; existing range/highlight tests remain required.

‎test/browser/review.spec.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,20 @@ test('resizes Conversation using its divider and keyboard',async({page})=>{
178178
await page.getByRole('button',{name:'Collapse conversation',exact:true}).click();await expect(divider).toBeHidden();
179179
await page.getByRole('button',{name:'Conversation',exact:true}).click();await expect(divider).toBeVisible();expect((await pane.boundingBox())!.width).toBe(480);
180180
});
181+
test('places selection actions beside code deep in a scrolled diff',async({page})=>{
182+
const repository=app.service.config.repository;
183+
writeFileSync(join(repository,'retry.ts'),Array.from({length:90},(_,i)=>`export const value${i} = ${i};`).join('\n')+'\n');
184+
execFileSync('git',['-c','core.hooksPath=/dev/null','commit','-am','Long diff'],{cwd:repository,stdio:'pipe'});
185+
let view=app.service.load();
186+
for(const key of view.segments.filter(s=>s.path==='retry.ts'&&['Unplanned','Ambiguous'].includes(s.row)).map(s=>s.key)) view=app.service.act({action:'assign',key,item:'P1',token:view.token});
187+
await page.goto(app.url);
188+
const line=page.locator('.added [data-line]').nth(60);await line.scrollIntoViewIfNeeded();await line.click();
189+
const actions=page.getByRole('group',{name:'Selected code'});await expect(actions).toBeVisible();
190+
const selection=(await line.boundingBox())!,toolbar=(await actions.boundingBox())!,code=(await page.locator('#code').boundingBox())!;
191+
expect(Math.min(Math.abs(toolbar.y+toolbar.height-selection.y),Math.abs(toolbar.y-selection.y-selection.height))).toBeLessThan(40);
192+
expect(toolbar.y).toBeGreaterThanOrEqual(code.y);expect(toolbar.y+toolbar.height).toBeLessThanOrEqual(code.y+code.height);
193+
await page.screenshot({path:test.info().outputPath('selection-actions.png')});
194+
await page.getByRole('button',{name:'Ask about selection',exact:true}).click();await expect(page.locator('#attachment')).toContainText('value60');
195+
await page.locator('#code').evaluate(element=>{element.scrollTop=0;});await expect(actions).toBeHidden();
196+
await line.scrollIntoViewIfNeeded();await expect(actions).toBeVisible();await page.getByRole('button',{name:'Clear selection',exact:true}).click();await expect(actions).toBeHidden();
197+
});

‎web/public/app.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,30 @@ function paintSelection() {
482482
element.classList.toggle("selected-line",active);
483483
if (element.matches("button")) element.setAttribute("aria-pressed",String(active));
484484
});
485+
positionSelectionActions();
485486
}
487+
function positionSelectionActions() {
488+
const toolbar = $("selection-actions");
489+
if (!snippetSelection) { toolbar.hidden = true; return; }
490+
const bounds = $("code").getBoundingClientRect();
491+
const visible = [...document.querySelectorAll("[data-code-line].selected-line")]
492+
.map(line => line.getBoundingClientRect())
493+
.filter(rect => rect.bottom > bounds.top && rect.top < bounds.bottom);
494+
if (!visible.length || bounds.width < 1) { toolbar.hidden = true; return; }
495+
const anchor = visible[visible.length - 1];
496+
toolbar.hidden = false;
497+
const inset = Math.min(140, bounds.width / 3);
498+
toolbar.style.width = `${Math.min(440, bounds.width - inset - 8)}px`;
499+
const height = toolbar.getBoundingClientRect().height;
500+
const below = anchor.bottom + 8;
501+
const top = below + height <= bounds.bottom - 8 ? below : anchor.top - height - 8;
502+
toolbar.style.left = `${bounds.left + inset}px`;
503+
toolbar.style.top = `${Math.max(bounds.top + 8, Math.min(top, bounds.bottom - height - 8))}px`;
504+
}
505+
$("code").addEventListener("scroll", positionSelectionActions);
506+
window.addEventListener("resize", positionSelectionActions);
507+
new ResizeObserver(positionSelectionActions).observe($("code"));
508+
486509
function renderAttachment() {
487510
const ref = attachments.get(`${selected}:${mode}`);
488511
$("attachment").hidden = !ref;

‎web/public/style.css‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ dialog::backdrop {
670670
.line-number { display: block; width: 100%; height: 18px; min-height: 0; padding: 0 8px 0 0; border: 0; border-radius: 0; background: transparent; color: var(--muted); font: inherit; line-height: 18px; text-align: right; }
671671
.code-lines [data-code-line] { display: inline-block; min-width: 100%; min-height: 18px; }
672672
.selected-line { background: var(--selected, #213448); }
673-
#selection-actions { position: sticky; top: 0; z-index: 2; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
673+
#selection-actions { position: fixed; z-index: 5; padding: 8px 12px; background: var(--raised); border: 1px solid var(--primary); border-radius: 4px; }
674+
#selection-actions button { margin: 4px 4px 0 0; }
675+
#snippet-ask { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
674676
#selection-label { display: block; overflow-wrap: anywhere; margin-bottom: 4px; }
675677
#attachment { border: 1px solid var(--line); padding: 8px; margin-bottom: 8px; overflow-wrap: anywhere; }
676678
#attachment small { display: block; color: var(--muted); }

0 commit comments

Comments
 (0)