Skip to content

Commit 374da5a

Browse files
authored
Merge pull request #3535 from lucasoshiro/clickable-prompt
[WIP] Executing cell when clicking its prompt
2 parents 893505a + 40cf1ab commit 374da5a

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

notebook/static/notebook/js/codecell.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ define([
160160

161161
var input = $('<div></div>').addClass('input');
162162
this.input = input;
163+
164+
var run_this_cell = $('<div></div>').addClass('run_this_cell');
165+
run_this_cell.prop('title', 'Run this cell');
166+
run_this_cell.append('<i class="fa-step-forward fa"></i>');
167+
run_this_cell.click(function (event) {
168+
event.stopImmediatePropagation();
169+
that.execute();
170+
});
171+
163172
var prompt = $('<div/>').addClass('prompt input_prompt');
164173
var inner_cell = $('<div/>').addClass('inner_cell');
165174
this.celltoolbar = new celltoolbar.CellToolbar({
@@ -180,7 +189,7 @@ define([
180189
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this));
181190
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
182191
inner_cell.append(input_area);
183-
input.append(prompt).append(inner_cell);
192+
input.append(run_this_cell).append(prompt).append(inner_cell);
184193

185194
var output = $('<div></div>');
186195
cell.append(input).append(output);
@@ -505,6 +514,7 @@ define([
505514
}
506515
this.input_prompt_number = number;
507516
var prompt_html = CodeCell.input_prompt_function(this.input_prompt_number, nline);
517+
508518
// This HTML call is okay because the user contents are escaped.
509519
this.element.find('div.input_prompt').html(prompt_html);
510520
this.events.trigger('set_dirty.Notebook', {value: true});

notebook/static/notebook/less/codecell.less

+25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ div.input_prompt {
2727
border-top: 1px solid transparent;
2828
}
2929

30+
.run_this_cell {
31+
visibility: hidden;
32+
cursor: pointer;
33+
color: #333;
34+
padding-top: 5px;
35+
padding-bottom: 5px;
36+
padding-left: 1ex;
37+
padding-right: 1ex;
38+
width: 1ex;
39+
}
40+
41+
div.code_cell div.input_prompt {
42+
min-width: 11ex;
43+
}
44+
45+
div.code_cell:hover .run_this_cell {
46+
visibility: visible;
47+
}
48+
49+
@media (-moz-touch-enabled: 1), (any-pointer: coarse) {
50+
.run_this_cell {
51+
visibility: visible;
52+
}
53+
}
54+
3055
// The styles related to div.highlight are for nbconvert HTML output only. This works
3156
// because the .highlight div isn't present in the live notebook. We could put this into
3257
// nbconvert, but it easily falls out of sync, can't use our less variables and doesn't

0 commit comments

Comments
 (0)