feat: add export and import functionality for snippets with UI controls

This commit is contained in:
2025-01-19 15:12:05 +02:00
parent f14f76e2f0
commit a8b2fa4be8
4 changed files with 72 additions and 0 deletions

View File

@@ -21,4 +21,28 @@ require(['vs/editor/editor.main'], async function () {
window.editor = editor;
snippetManager.setEditor(editor);
document.getElementById('export-snippets').addEventListener('click', () => {
snippetManager.storageManager.exportSnippets();
});
document.getElementById('import-snippets').addEventListener('click', () => {
document.getElementById('import-file').click();
});
document.getElementById('import-file').addEventListener('change', async (e) => {
if (e.target.files.length > 0) {
try {
const snippets = await snippetManager.storageManager.importSnippets(e.target.files[0]);
snippetManager.snippets = snippets;
snippetManager.uiManager.renderSnippetList(snippets, snippetManager.currentSnippetId);
if (snippets.length > 0) {
snippetManager.loadSnippet(snippets[0].id);
}
e.target.value = ''; // Reset file input
} catch (err) {
alert(err.message);
}
}
});
});