Skip to content

Commit 0273b3f

Browse files
authored
Merge pull request #2039 from jupyter/auto-backport-of-pr-1482
Backport PR #1482 on branch 4.x
2 parents 4727efc + 5302351 commit 0273b3f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

notebook/static/notebook/js/cell.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,20 @@ define([
479479
if (data.metadata !== undefined) {
480480
this.metadata = data.metadata;
481481
}
482+
// upgrade cell's editable metadata if not defined
483+
if (this.metadata.editable === undefined) {
484+
this.metadata.editable = this.is_editable();
485+
}
486+
// upgrade cell's deletable metadata if not defined
487+
if (this.metadata.deletable === undefined) {
488+
this.metadata.deletable = this.is_deletable();
489+
}
482490
};
483491

484492

485493
/**
486494
* can the cell be split into two cells (false if not deletable)
495+
*
487496
* @method is_splittable
488497
**/
489498
Cell.prototype.is_splittable = function () {
@@ -500,14 +509,28 @@ define([
500509
};
501510

502511
/**
503-
* is the cell deletable? only false (undeletable) if
504-
* metadata.deletable is explicitly false -- everything else
512+
* is the cell edtitable? only false (readonly) if
513+
* metadata.editable is explicitly false -- everything else
505514
* counts as true
506515
*
516+
* @method is_editable
517+
**/
518+
Cell.prototype.is_editable = function () {
519+
if (this.metadata.editable === false) {
520+
return false;
521+
}
522+
return true;
523+
};
524+
525+
/**
526+
* is the cell deletable? only false (undeletable) if
527+
* metadata.deletable is explicitly false or if the cell is not
528+
* editable -- everything else counts as true
529+
*
507530
* @method is_deletable
508531
**/
509532
Cell.prototype.is_deletable = function () {
510-
if (this.metadata.deletable === false) {
533+
if (this.metadata.deletable === false || !this.is_editable()) {
511534
return false;
512535
}
513536
return true;

notebook/static/notebook/js/codecell.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ define([
177177
if (that.keyboard_manager) {
178178
that.keyboard_manager.enable();
179179
}
180+
181+
that.code_mirror.setOption('readOnly', !that.is_editable());
180182
});
181183
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this));
182184
$(this.code_mirror.getInputField()).attr("spellcheck", "false");

notebook/static/notebook/js/textcell.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ define([
104104
if (that.keyboard_manager) {
105105
that.keyboard_manager.enable();
106106
}
107+
that.code_mirror.setOption('readOnly', !that.is_editable());
107108
});
108109
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
109110
// The tabindex=-1 makes this div focusable.

0 commit comments

Comments
 (0)