Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
67 changes: 63 additions & 4 deletions staged/src/lib/features/notes/NoteModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Read-only view.
-->
<script lang="ts">
import { X } from 'lucide-svelte';
import { X, Copy, Check } from 'lucide-svelte';
import { marked } from 'marked';
import { sanitize } from '../../shared/sanitize';
import { handleExternalLinkClick } from '../../commands';
Expand All @@ -20,10 +20,23 @@

let { title, content, onClose }: Props = $props();

let copied = $state(false);

function renderMarkdown(text: string): string {
return sanitize(marked.parse(text) as string);
}

async function handleShare() {
const text = title ? `# ${title}\n\n${content}` : content;
try {
await navigator.clipboard.writeText(text);
copied = true;
setTimeout(() => (copied = false), 1500);
} catch {
// clipboard API may fail in some contexts
}
}

function handleKeydown(e: KeyboardEvent) {
if (e.key === 'Escape') {
e.preventDefault();
Expand Down Expand Up @@ -53,9 +66,23 @@
<div class="modal" role="presentation" onclick={(e) => e.stopPropagation()}>
<header class="modal-header">
<h2 class="modal-title">{title}</h2>
<button class="close-btn" onclick={onClose} title="Close (Esc)">
<X size={16} />
</button>
<div class="header-actions">
<button
class="share-btn"
class:copied
onclick={handleShare}
title={copied ? 'Copied!' : 'Copy note to clipboard'}
>
{#if copied}
<Check size={16} />
{:else}
<Copy size={16} />
{/if}
</button>
<button class="close-btn" onclick={onClose} title="Close (Esc)">
<X size={16} />
</button>
</div>
</header>
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
<div class="modal-content" onclick={handleExternalLinkClick}>
Expand Down Expand Up @@ -135,6 +162,38 @@
background: var(--bg-hover);
}

.header-actions {
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
}

.share-btn {
display: flex;
align-items: center;
justify-content: center;
padding: 4px;
background: none;
border: none;
border-radius: 6px;
color: var(--text-muted);
cursor: pointer;
flex-shrink: 0;
transition:
color 0.1s,
background-color 0.1s;
}

.share-btn:hover {
color: var(--text-primary);
background: var(--bg-hover);
}

.share-btn.copied {
color: var(--ui-success);
}

.modal-content {
flex: 1;
overflow-y: auto;
Expand Down