Skip to content

Commit 0b9709c

Browse files
committed
add run cell shortcut
1 parent 9ad7631 commit 0b9709c

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

notebookjs/src/public/javascripts/index.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ const editor = CodeMirror(document.getElementById('div-1'), {
88
autoCloseBrackets: true
99
});
1010

11-
//run first cell on double click
12-
$(`#div-1`).dblclick(function () {
13-
exec_cell(`run_div-1`);
11+
//run first cell on CTRL ENTER Pressed
12+
$(`#div-1`).keydown(function (e) {
13+
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
14+
document.getElementById("cell_spinner-1").style.display = "block"
15+
document.getElementById("cell_num-1").style.display = "none"
16+
exec_cell(`run_div-1`);
17+
18+
}
1419
});
1520

21+
22+
1623
var md = new Remarkable()
1724
//Global Params
1825
let vars_in_scope = {
@@ -59,7 +66,12 @@ function exec_cell(c_id) {
5966
}
6067
}
6168

62-
$(`#out_${id}`).html(output);
69+
Promise.resolve(output).then((val) => {
70+
$(`#out_${id}`).html(val);
71+
document.getElementById("cell_spinner-1").style.display = "none"
72+
document.getElementById("cell_num-1").style.display = "block"
73+
})
74+
6375

6476
count = parseInt(count) + 1
6577
let div_count = `div-${count}`
@@ -159,9 +171,14 @@ function add_new_code_cell(c_id, where) {
159171
});
160172

161173

162-
//run cell on double click
163-
$(`#div-${new_id}`).dblclick(function () {
164-
exec_cell(`run_div-${new_id}`);
174+
//run cell on CTRL-ENTER Pressed
175+
$(`#div-${new_id}`).keydown(function (e) {
176+
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
177+
document.getElementById("cell_spinner-1").style.display = "block"
178+
document.getElementById("cell_num-1").style.display = "none"
179+
exec_cell(`run_div-${new_id}`);
180+
181+
}
165182
});
166183

167184
}
@@ -245,7 +262,6 @@ function add_new_text_cell(c_id, where) {
245262
document.getElementById(`btn-actions-${new_id}`).style.display = "none"
246263
});
247264

248-
249265
}
250266

251267
function delete_cell(id) {
@@ -262,13 +278,13 @@ function delete_cell(id) {
262278

263279

264280
$(document).on("click", "button.run", function () {
265-
console.log(this.id);
266-
267281
if (this.id.split("_").includes("md")) {
268282
let id = this.id.split("-")[1]
269283
let val = document.getElementById(`text-box_${id}`).value
270284
show_md(id, val)
271285
} else {
286+
document.getElementById("cell_spinner-1").style.display = "block"
287+
document.getElementById("cell_num-1").style.display = "none"
272288
exec_cell(this.id);
273289
}
274290
})
@@ -315,6 +331,7 @@ function show_md(id, value) {
315331
document.getElementById(div_id).style.display = "none"
316332
}
317333

334+
318335
$(document).on("dblclick", "div.text-out-box", function () {
319336
let id = this.id.split("_")[1]
320337
md_id = `text-div_${id}`

notebookjs/src/views/index.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<div class="">
44
<div class="row" style="margin-top: 50px;" id="cell-1">
55
<div class="col-md-1">
6-
<p id="cell-num" class="code_symbol">[1]</p>
6+
<div id="cell_spinner-1" class="spinner-border text-info code_symbol" style="display: none;" role="status">
7+
<span class="sr-only">Loading...</span>
8+
</div>
9+
<p id="cell_num-1" class="code_symbol">[1]</p>
710
</div>
811
<div id="div-1" class="col-md-9">
912
<div id="btn-actions-1" class="btn-group-horizontal" style="display: none;">

notebookjs/src/views/layout.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<li class="nav-item dropdown active">
7373
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
7474
aria-haspopup="true" aria-expanded="false">
75-
File
75+
Options
7676
</a>
7777
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
7878
<a class="dropdown-item" id="download" href="#">Download Notebook</a>

0 commit comments

Comments
 (0)