Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 101 additions & 15 deletions apps/editor/e2e/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const git = (cwd: string, ...args: string[]) =>
const commitPanel = (page: Page) => page.getByRole('region', { name: 'Commit', exact: true });
const logPanel = (page: Page) => page.getByRole('region', { name: 'Git', exact: true });
const group = (page: Page, name: string) =>
commitPanel(page).getByRole('region', { name, exact: true });
commitPanel(page).getByRole('treeitem', { name: new RegExp(`^${name}, \\d+ files?\\b`) });
const row = (page: Page, list: string, path: string) =>
group(page, list).getByRole('option', { name: path, exact: true });
group(page, list).getByRole('treeitem', { name: path, exact: true });
const vcs = async (page: Page, entry: string) => {
await page.getByRole('button', { name: 'VCS', exact: true }).click();
await page
Expand All @@ -40,6 +40,22 @@ const commit = async (page: Page, text: string, button = 'Commit') => {
const branchStatus = (page: Page, text: string) =>
page.getByRole('contentinfo').getByRole('button', { name: text, exact: true });
const commits = (page: Page) => logPanel(page).getByRole('grid', { name: 'Commits' });
/**
* Controls inside a role whose children are presentational (axe `nested-interactive`), as
* `outer > inner` names. Hidden or `tabindex="-1"` controls count: they are still in the DOM.
*/
const nestedControls = (page: Page) =>
commitPanel(page).evaluate((panel) => {
const name = (element: Element) =>
element.getAttribute('aria-label') ?? element.getAttribute('role') ?? element.localName;
const controls =
'button, input, select, textarea, a[href], [tabindex], [role="button"], [role="checkbox"], [role="option"]';
return [
...panel.querySelectorAll('button, [role="button"], [role="option"], [role="checkbox"]'),
].flatMap((outer) =>
[...outer.querySelectorAll(controls)].map((inner) => `${name(outer)} > ${name(inner)}`),
);
});

const original = readFileSync(join(PONG, FILE), 'utf8');
const otherOriginal = readFileSync(join(PONG, OTHER_FILE), 'utf8');
Expand Down Expand Up @@ -105,7 +121,6 @@ test('initializes a repository, commits what is checked and shows the log', asyn
await expect(commitButton(page)).toBeDisabled();
const includeAll = group(page, 'Unversioned files').getByRole('checkbox', {
name: 'Include all: Unversioned files',
includeHidden: true,
});
await nested.getByRole('checkbox').check();
expect(await includeAll.evaluate((box: HTMLInputElement) => box.indeterminate)).toBe(true);
Expand Down Expand Up @@ -150,14 +165,10 @@ test('shows a change in the Files panel and as a diff, and keeps the panel state
await page.getByRole('tab', { name: 'rename-me.txt' }).click({ button: 'middle' });
await page.getByRole('tab', { name: 'Project', exact: true }).click();

await group(page, 'Changes')
.getByRole('button', { name: 'Collapse Changes', includeHidden: true })
.click();
await group(page, 'Changes').locator('.chevron').click();
await expect(changed(page)).toHaveCount(0);
await expect(group(page, 'Changes')).toContainText('1 file');
await group(page, 'Changes')
.getByRole('button', { name: 'Expand Changes', includeHidden: true })
.click();
await group(page, 'Changes').locator('.chevron').click();
await expect(changed(page)).toBeVisible();

await changed(page)
Expand All @@ -182,7 +193,7 @@ test('selects changes, rolls them back, adds and deletes an unversioned file', a

const rollBack = commitPanel(page).getByRole('button', { name: 'Rollback' });
await commitPanel(page)
.getByRole('group', { name: 'Changed files' })
.getByRole('tree', { name: 'Changed files' })
.click({
position: { x: 100, y: 200 },
});
Expand Down Expand Up @@ -295,8 +306,9 @@ test('pushes, fetches, filters the log, merges a conflict and pushes the merge',
await expect(page.getByText('The update stopped on conflicts').last()).toBeVisible();
const conflict = row(page, 'Merge conflicts', FILE);
await expect(conflict).toBeVisible();
expect(await nestedControls(page)).toEqual([]);
writeFileSync(join(PONG, FILE), 'both\n');
await conflict.getByRole('button', { name: 'Mark resolved' }).click();
await conflict.getByRole('button', { name: `Mark resolved: ${FILE}` }).click();
await expect(group(page, 'Merge conflicts')).toHaveCount(0);
await commit(page, 'merge', 'Commit and push…');
const afterMerge = await pushDialog(page);
Expand Down Expand Up @@ -387,18 +399,27 @@ test('browses, folds and includes changes from the keyboard', async ({ page }) =
await resetLayout(page);
await showPanel(page, 'Commit');
await vcs(page, 'Initialize repository');
const files = commitPanel(page).getByRole('group', { name: 'Changed files' });
const node = commitPanel(page).getByRole('button', { name: /^Unversioned files, / });
const files = commitPanel(page).getByRole('tree', { name: 'Changed files' });
const node = commitPanel(page).getByRole('treeitem', { name: /^Unversioned files, / });
const includeAll = commitPanel(page).getByRole('checkbox', {
name: 'Include all: Unversioned files',
includeHidden: true,
});
const active = () =>
files.evaluate(
(list) =>
document.getElementById(list.getAttribute('aria-activedescendant') ?? '')?.ariaLabel ?? '',
);
/** The outline of the row at the cursor, or of the group node's header. */
const cursorOutline = () =>
files.evaluate((list) => {
const item = document.getElementById(list.getAttribute('aria-activedescendant') ?? '');
const shown = item?.hasAttribute('aria-expanded')
? item.querySelector(':scope > .group')
: item;
return shown ? getComputedStyle(shown).outlineStyle : '';
});
await expect(node).toBeVisible();
expect(await nestedControls(page)).toEqual([]);
await files.focus();
await page.keyboard.press('ArrowDown');
await expect.poll(active).toMatch(/^Changes, 0 files/);
Expand All @@ -415,10 +436,75 @@ test('browses, folds and includes changes from the keyboard', async ({ page }) =
await page.keyboard.press('ArrowRight');
await expect.poll(active).not.toMatch(/^Unversioned files/);
await expect(
group(page, 'Unversioned files').getByRole('option', { selected: true }),
group(page, 'Unversioned files').getByRole('treeitem', { selected: true }),
).toHaveCount(1);
await page.keyboard.press('ArrowLeft');
await expect.poll(active).toMatch(/^Unversioned files, /);
await expect.poll(cursorOutline).toBe('solid');

await page.keyboard.press('ArrowRight');
await expect.poll(active).not.toMatch(/^Unversioned files/);
await expect.poll(cursorOutline).toBe('solid');
for (let press = 0; press < 45; press++) await page.keyboard.press('ArrowDown');
await page.keyboard.press('ArrowLeft');
await expect.poll(active).toMatch(/^Unversioned files, /);
await expect(node.getByText('Unversioned files', { exact: true })).toBeInViewport();

await page.keyboard.press('ArrowRight');
await expect.poll(active).not.toMatch(/^Unversioned files/);
await commitPanel(page).getByRole('button', { name: 'Collapse all' }).click();
await expect.poll(active).toMatch(/^Unversioned files, /);
await commitPanel(page).getByRole('button', { name: 'Expand all' }).click();
await resetLayout(page);
await saved(page);
});

test('fits the log filter bar in a 1280x720 window', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 720 });
initRepository();
await open(page);
await showPanel(page, 'Git');
const bar = logPanel(page).getByRole('textbox', { name: 'Text or hash' }).locator('..');
await expect(bar).toBeVisible();
const fit = await bar.evaluate((filters) => {
const box = filters.getBoundingClientRect();
const lines = (element: Element) => {
const range = document.createRange();
range.selectNodeContents(element);
return new Set([...range.getClientRects()].map((rect) => Math.round(rect.top))).size;
};
return {
overflow: filters.scrollWidth - filters.clientWidth,
outside: [...filters.children]
.filter((child) => {
const rect = child.getBoundingClientRect();
return rect.left < box.left - 0.5 || rect.right > box.right + 0.5;
})
.map((child) => child.getAttribute('aria-label') ?? child.textContent),
wrapped: [...filters.querySelectorAll('[aria-label="User"], [aria-label="Date"]')]
.filter((trigger) => lines(trigger.querySelector('span')!) > 1)
.map((trigger) => trigger.getAttribute('aria-label')),
input: filters.querySelector('input')!.getBoundingClientRect().width,
wide: [...filters.querySelectorAll('[aria-label="User"], [aria-label="Date"]')]
.filter((trigger) => trigger.getBoundingClientRect().width >= box.width / 2)
.map((trigger) => trigger.getAttribute('aria-label')),
rows: new Set(
[...filters.children]
.map((child) => child.getBoundingClientRect())
.filter((rect) => rect.width > 0 && rect.height > 0)
.map((rect) => Math.round((rect.top + rect.bottom) / 8)),
).size,
};
});
expect(fit).toEqual({
overflow: 0,
outside: [],
wrapped: [],
wide: [],
input: expect.any(Number),
rows: expect.any(Number),
});
expect(fit.input).toBeGreaterThanOrEqual(140);
/** The default commits column is about 181 px wide: input, branch and two selects take 3 rows. */
expect(fit.rows).toBeLessThanOrEqual(3);
});
4 changes: 2 additions & 2 deletions apps/editor/e2e/tutorial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ test('the tutorial: from the welcome to a first commit', async ({ page }) => {
await press(page, 'Show Commit');
const commit = page.getByRole('region', { name: 'Commit', exact: true });
await commit
.getByRole('region', { name: 'Unversioned files', exact: true })
.getByRole('checkbox', { name: 'Include all: Unversioned files', includeHidden: true })
.getByRole('treeitem', { name: /^Unversioned files, / })
.getByRole('checkbox', { name: 'Include all: Unversioned files' })
.check();
await commit.getByRole('textbox', { name: 'Commit message' }).fill('my first game');
await commit.getByRole('button', { name: 'Commit', exact: true }).click();
Expand Down
34 changes: 22 additions & 12 deletions plugins/git/src/widgets/commit/ChangeGroupNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
ondiff: (row: FileRow) => void;
/** Id of a row or of the group node (`group:<id>`), for the list's active descendant. */
idOf: (stop: string) => string;
/** The stop at the keyboard's cursor, outlined while the tree has the focus. */
cursor: string | undefined;
}

const {
Expand All @@ -35,6 +37,7 @@
oncheck,
ondiff,
idOf,
cursor,
}: Props = $props();
const { actions: act } = getSession();
const count = $derived(group.rows.filter((row) => checked.has(row.file.path)).length);
Expand All @@ -43,11 +46,12 @@
{#snippet fileRow(row: FileRow, checkable: boolean)}
<li
id={idOf(row.file.path)}
role="option"
role="treeitem"
aria-label={row.file.path}
aria-describedby={`${idOf(row.file.path)}-status`}
aria-selected={selected.includes(row.file.path)}
class:selected={selected.includes(row.file.path)}
class:cursor={cursor === row.file.path}
data-path={row.file.path}
title={`${row.title}: ${row.file.path}`}
onclick={(event) => onselect(event, row.file.path)}
Expand Down Expand Up @@ -81,6 +85,7 @@
<Button
size="sm"
variant="ghost"
aria-label={`Mark resolved: ${row.file.path}`}
onclick={(event) => {
event.stopPropagation();
void act.markResolved(row.file.path);
Expand All @@ -90,24 +95,25 @@
</li>
{/snippet}

<section aria-label={group.title}>
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_interactive_supports_focus -->
<div
id={idOf(`group:${group.id}`)}
role="treeitem"
aria-selected={active}
aria-expanded={!folded}
aria-label={`${group.title}, ${group.rows.length} ${group.rows.length === 1 ? 'file' : 'files'}${group.checkable ? `, ${count} included` : ''}`}
>
<div
id={idOf(`group:${group.id}`)}
class="group"
class:selected={active}
role="button"
aria-expanded={!folded}
aria-label={`${group.title}, ${group.rows.length} ${group.rows.length === 1 ? 'file' : 'files'}${group.checkable ? `, ${count} included` : ''}`}
class:cursor={cursor === `group:${group.id}`}
role="presentation"
onclick={onselectgroup}
>
<button
type="button"
class="chevron"
tabindex="-1"
aria-hidden="true"
aria-expanded={!folded}
aria-label={`${folded ? 'Expand' : 'Collapse'} ${group.title}`}
onclick={(event) => {
event.stopPropagation();
onfold(!folded);
Expand All @@ -119,7 +125,6 @@
<input
type="checkbox"
tabindex="-1"
aria-hidden="true"
aria-label={`Include all: ${group.title}`}
checked={group.rows.length > 0 && count === group.rows.length}
indeterminate={count > 0 && count < group.rows.length}
Expand All @@ -136,7 +141,7 @@
<span class="count">{group.rows.length} {group.rows.length === 1 ? 'file' : 'files'}</span>
</div>
{#if !folded}
<ul role="listbox" aria-multiselectable="true" aria-label={`${group.title}: files`}>
<ul role="group" aria-label={`${group.title}: files`}>
{#each group.rows.slice(0, MAX_ROWS) as row (row.file.path)}
{@render fileRow(row, group.checkable)}
{/each}
Expand All @@ -148,7 +153,7 @@
</p>
{/if}
{/if}
</section>
</div>

<style>
input[type='checkbox'] {
Expand Down Expand Up @@ -197,6 +202,11 @@
user-select: none;
white-space: nowrap;
}
:global(.scroll:focus) li.cursor,
:global(.scroll:focus) .group.cursor {
outline: 1px solid var(--nf-color-focus);
outline-offset: -1px;
}
.name {
min-width: 0;
overflow: hidden;
Expand Down
20 changes: 15 additions & 5 deletions plugins/git/src/widgets/commit/ChangesTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,23 @@
const group = stop.startsWith(GROUP_STOP) ? groupOf(stop) : undefined;
if (group) panel.selectGroup(group);
else select({ shiftKey, ctrlKey: false, metaKey: false }, stop);
document.getElementById(idOf(stop))?.scrollIntoView({ block: 'nearest' });
const element = document.getElementById(idOf(stop));
(group ? element?.querySelector(':scope > .group') : element)?.scrollIntoView({
block: 'nearest',
});
};
/** The stop at the cursor if it is drawn, else its group node (a fold or `MAX_ROWS` hid it). */
const shown = $derived.by(() => {
if (!current || stops.includes(current)) return current;
const group = groupOf(current);
return group && `${GROUP_STOP}${group.id}`;
});

const onkeydown = (event: KeyboardEvent) =>
onChangesKey(event, {
panel,
stops,
current,
current: shown,
visiblePaths,
selectedRows,
unversionedSelected,
Expand Down Expand Up @@ -243,13 +252,13 @@
/>
</div>
<ContextMenu items={rowMenu}>
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
<div
class="scroll"
role="group"
role="tree"
aria-multiselectable="true"
aria-label="Changed files"
aria-busy={$git.reading || busy}
aria-activedescendant={current ? idOf(current) : undefined}
aria-activedescendant={shown ? idOf(shown) : undefined}
aria-keyshortcuts="ArrowUp ArrowDown ArrowLeft ArrowRight Space Enter"
tabindex="0"
{onkeydown}
Expand All @@ -265,6 +274,7 @@
<ChangeGroupNode
{group}
{idOf}
cursor={shown}
folded={panel.isFolded(group)}
active={panel.selectedGroup === group.id}
selected={panel.selected}
Expand Down
10 changes: 8 additions & 2 deletions plugins/git/src/widgets/log/CommitTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,20 @@
.filters {
display: flex;
flex: none;
gap: var(--nf-space-2);
flex-wrap: wrap;
gap: 2px var(--nf-space-1);
align-items: center;
padding: 2px var(--nf-space-2);
border-bottom: 1px solid var(--nf-color-border);
}
.filters :global(input) {
flex: 1;
min-width: 80px;
min-width: 140px;
}
.filters :global(.nf-select-trigger) {
flex: none;
width: auto;
white-space: nowrap;
}
.filter {
flex: none;
Expand Down
Loading