mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2025-12-21 21:22:25 +00:00
feat: add duplicate snippet functionality in SnippetManager and UI
This commit is contained in:
@@ -157,6 +157,21 @@ export class SnippetManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duplicateSnippet(id) {
|
||||||
|
const snippet = this.snippets.find(s => s.id === id);
|
||||||
|
if (!snippet) return;
|
||||||
|
|
||||||
|
const newSnippet = {
|
||||||
|
...snippet,
|
||||||
|
id: 'snippet-' + Date.now(),
|
||||||
|
name: snippet.name + ' (Copy)'
|
||||||
|
};
|
||||||
|
|
||||||
|
this.snippets.push(newSnippet);
|
||||||
|
this.saveSnippetsAndUpdateUI();
|
||||||
|
this.loadSnippet(newSnippet.id);
|
||||||
|
}
|
||||||
|
|
||||||
saveSnippetsAndUpdateUI() {
|
saveSnippetsAndUpdateUI() {
|
||||||
this.storageManager.saveSnippets(this.snippets);
|
this.storageManager.saveSnippets(this.snippets);
|
||||||
this.updateUI();
|
this.updateUI();
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ export class UIManager {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.snippetManager.deleteSnippet(snippet.id);
|
this.snippetManager.deleteSnippet(snippet.id);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
buttonsDiv.appendChild(this.createButton('📄', 'duplicate-snippet', (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
this.snippetManager.duplicateSnippet(snippet.id);
|
||||||
|
}));
|
||||||
|
|
||||||
div.appendChild(buttonsDiv);
|
div.appendChild(buttonsDiv);
|
||||||
container.appendChild(div);
|
container.appendChild(div);
|
||||||
|
|||||||
@@ -249,4 +249,22 @@
|
|||||||
|
|
||||||
.snippet-item:hover .edit-snippet {
|
.snippet-item:hover .edit-snippet {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.duplicate-snippet {
|
||||||
|
opacity: 0.4;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 2px 4px;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
min-width: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.duplicate-snippet:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.snippet-item:hover .duplicate-snippet {
|
||||||
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user