mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-12-02 19:40:35 +08:00
explorer: Select the whole command on click
This commit is contained in:
@@ -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} />
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user