mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2025-12-21 21:22:25 +00:00
feat: add export and import functionality for snippets with UI controls
This commit is contained in:
24
src/main.js
24
src/main.js
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user