Skip to content

Commit 1709a44

Browse files
committed
Added initial add_snippet_to_storage function
1 parent 885e383 commit 1709a44

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

notebook-snippet-manager.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ define(['base/js/namespace', 'jquery', 'base/js/dialog'], function(Jupyter, $, d
1111
}
1212
}
1313

14+
function add_snippet_to_storage(snippet_name, snippet_content) {
15+
var storage = window['localStorage'];
16+
var updated_snippets = storage.getItem('JupyterNotebookSnippets');
17+
if (updated_snippets == null) {
18+
updated_snippets = {};
19+
}
20+
updated_snippets[snippet_name] = snippet_content;
21+
storage.setItem('JupyterNotebookSnippets', updated_snippets);
22+
}
23+
1424
function add_cell_to_snippet_manager() {
1525
var selected_cell = Jupyter.notebook.get_selected_cell();
1626
var selected_content = selected_cell.get_text();
@@ -31,7 +41,8 @@ define(['base/js/namespace', 'jquery', 'base/js/dialog'], function(Jupyter, $, d
3141
OK: {
3242
'class': 'btn-primary',
3343
'click': function() {
34-
console.log('Adding to snippet manager...');
44+
var snippet_name = $('input[name=snippet-name]').val();
45+
add_snippet_to_storage(snippet_name, selected_contet);
3546
}
3647
}
3748
}

0 commit comments

Comments
 (0)