explorer: Select the whole command on click

This commit is contained in:
Daniel Norman
2026-11-30 12:08:38 +01:00
parent 98d32231fc
commit 96bdcb03a6
2 changed files with 19 additions and 3 deletions
+14 -3
View File
@@ -4,6 +4,16 @@
export let command: string;
export let fullWidth: boolean = false;
export let showPrompt: boolean = true;
let text: HTMLSpanElement;
// Select the whole command on a plain click, but keep a dragged selection.
function selectCommand() {
const selection = window.getSelection();
if (selection?.isCollapsed) {
selection.selectAllChildren(text);
}
}
</script>
<style>
@@ -33,7 +43,6 @@
scrollbar-width: none;
}
.prompt {
margin-right: 1ch;
user-select: none;
}
.clipboard {
@@ -55,8 +64,10 @@
<div class="wrapper" class:full-width={fullWidth}>
<div class="cmd" class:full-width={fullWidth}>
<div class="text">
{#if showPrompt}<span class="prompt">$</span>{/if}{command}
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
<div class="text" on:click={selectCommand}>
{#if showPrompt}<span class="prompt">$</span>{/if}
<span bind:this={text}>{command}</span>
</div>
<div class="clipboard">
<Clipboard text={command} />
+5
View File
@@ -45,6 +45,11 @@ test("copy to clipboard", async ({ page, browserName, context }) => {
.first()
.click();
await expectClipboard(`rad clone ${sourceBrowsingRid}`);
await page.getByText(`rad clone ${sourceBrowsingRid}`).click();
expect(await page.evaluate(() => window.getSelection()?.toString())).toBe(
`rad clone ${sourceBrowsingRid}`,
);
}
// `git clone` URL.