diff --git a/index.html b/index.html index 251e948..ad1d2f4 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ - +
diff --git a/src/SnippetManager.js b/src/SnippetManager.js index f2b6244..3b63ef2 100644 --- a/src/SnippetManager.js +++ b/src/SnippetManager.js @@ -149,4 +149,22 @@ export class SnippetManager { this.readOnlyMode = hasChanges && !this.isDraftVersion; this.editorManager.updateReadOnlyState(this.readOnlyMode); } + + deleteSnippet(id) { + if (confirm('Are you sure you want to delete this snippet?')) { + this.snippets = this.snippets.filter(s => s.id !== id); + this.storageManager.saveSnippets(this.snippets); + + if (this.currentSnippetId === id) { + this.currentSnippetId = null; + if (this.snippets.length > 0) { + this.loadSnippet(this.snippets[0].id); + } else { + this.editorManager.setValue(''); + } + } + + this.uiManager.renderSnippetList(this.snippets, this.currentSnippetId); + } + } } \ No newline at end of file diff --git a/src/UIManager.js b/src/UIManager.js index 5d9e979..80adf93 100644 --- a/src/UIManager.js +++ b/src/UIManager.js @@ -19,10 +19,25 @@ export class UIManager { snippets.forEach(snippet => { const div = document.createElement('div'); div.className = `snippet-item ${snippet.id === currentSnippetId ? 'active' : ''}`; + div.onclick = () => this.snippetManager.loadSnippet(snippet.id); + const hasChanges = this.snippetManager.hasDraftChanges(snippet.id); const indicator = hasChanges ? '🟡' : '🟢'; - div.textContent = `${indicator} ${snippet.name}`; - div.onclick = () => this.snippetManager.loadSnippet(snippet.id); + + const contentDiv = document.createElement('div'); + contentDiv.className = 'snippet-content'; + contentDiv.textContent = `${indicator} ${snippet.name}`; + div.appendChild(contentDiv); + + const deleteButton = document.createElement('button'); + deleteButton.className = 'delete-snippet'; + deleteButton.innerHTML = '❌'; + deleteButton.onclick = (e) => { + e.stopPropagation(); + this.snippetManager.deleteSnippet(snippet.id); + }; + div.appendChild(deleteButton); + container.appendChild(div); }); } diff --git a/styles.css b/src/styles.css similarity index 75% rename from styles.css rename to src/styles.css index 6fadea4..7b80a91 100644 --- a/styles.css +++ b/src/styles.css @@ -107,4 +107,42 @@ display: flex; gap: 0.5rem; align-items: center; +} + +.snippet-item { + display: flex; + justify-content: space-between; + align-items: center; + padding: 8px; + cursor: pointer; + gap: 8px; +} + +.snippet-item span { + cursor: pointer; +} + +.snippet-content { + flex: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.delete-snippet { + opacity: 0.4; + font-size: 14px; + padding: 2px 4px; + background: none; + border: none; + cursor: pointer; + min-width: 24px; +} + +.delete-snippet:hover { + opacity: 1; +} + +.snippet-item:hover .delete-snippet { + opacity: 0.8; } \ No newline at end of file