mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:02:51 +00:00
fix(ui): stop double-clicking tree rows from selecting label text (#2726)
The second press of a double-click started the browser's word selection, which in the virtualized tree spilled onto the rows an expanding folder had just inserted. Tree cancels the default of repeated presses; the first press still selects and dblclick still activates. Fixes #2713 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com>
This commit is contained in:
@@ -535,3 +535,33 @@ describe("Tree indents", () => {
|
||||
expect(placeholder?.style.paddingLeft).toBe("calc(24px + 1 * var(--tree-indent, 20px))");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tree double-click", () => {
|
||||
it("selects on the first press without cancelling its default", () => {
|
||||
const { tree } = setup();
|
||||
const row = within(tree).getByRole("treeitem", { name: "README.md" });
|
||||
expect(fireEvent.mouseDown(row, { button: 0, detail: 1 })).toBe(true);
|
||||
expect(row).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
it("cancels the second press so double-clicking cannot select label text, and still activates", () => {
|
||||
const { tree, onActivate } = setup();
|
||||
const row = within(tree).getByRole("treeitem", { name: "README.md" });
|
||||
fireEvent.mouseDown(row, { button: 0, detail: 1 });
|
||||
// The browser starts its word selection on this press; cancelling it keeps
|
||||
// the labels unselected (jsdom reports cancellation through dispatchEvent).
|
||||
expect(fireEvent.mouseDown(row, { button: 0, detail: 2 })).toBe(false);
|
||||
fireEvent.doubleClick(row);
|
||||
expect(onActivate).toHaveBeenCalledWith(expect.objectContaining({ id: "README.md" }), expect.anything());
|
||||
expect(row).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
it("still expands a folder on double-click", () => {
|
||||
const { tree } = setup();
|
||||
const row = within(tree).getByRole("treeitem", { name: "src" });
|
||||
fireEvent.mouseDown(row, { button: 0, detail: 1 });
|
||||
fireEvent.mouseDown(row, { button: 0, detail: 2 });
|
||||
fireEvent.doubleClick(row);
|
||||
expect(labels(tree)).toEqual(["src", "main", "util.ts", "README.md"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -590,6 +590,17 @@ export function Tree<T>(props: TreeProps<T>) {
|
||||
return;
|
||||
}
|
||||
if (e.button !== 0) return;
|
||||
// The second press of a double-click starts the browser's word selection,
|
||||
// which in a virtualized tree spills onto the rows an expanding folder just
|
||||
// inserted and highlights neighbouring labels. Prevent it: rows are
|
||||
// controls, not text (the shared List does the same via `user-select`), the
|
||||
// first press already selected, and the dblclick below still fires, so
|
||||
// activation keeps working. Rows can host editors (inline rename), so this
|
||||
// is scoped to repeated clicks instead of unselecting all row content.
|
||||
if (e.detail >= 2) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
setQuery("");
|
||||
if (e.shiftKey) selectIndex(i, "range");
|
||||
else if (e.metaKey || e.ctrlKey) selectIndex(i, "toggle");
|
||||
|
||||
Reference in New Issue
Block a user