UNPKG

jupyterlab-emrys

Version:

A computational environment for Jupyter. Powered by Emrys

87 lines (86 loc) 2.66 kB
// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var CodeMirror = require('codemirror'); require('codemirror/mode/meta'); require('codemirror/lib/codemirror.css'); var phosphor_widget_1 = require('phosphor-widget'); /** * The class name added to CodeMirrorWidget instances. */ var EDITOR_CLASS = 'jp-CodeMirrorWidget'; /** * A widget which hosts a CodeMirror editor. */ var CodeMirrorWidget = (function (_super) { __extends(CodeMirrorWidget, _super); /** * Construct a CodeMirror widget. */ function CodeMirrorWidget(options) { _super.call(this); this._editor = null; this._needsRefresh = true; this.addClass(EDITOR_CLASS); this._editor = CodeMirror(this.node, options); } /** * Dispose of the resources held by the widget. */ CodeMirrorWidget.prototype.dispose = function () { this._editor = null; _super.prototype.dispose.call(this); }; Object.defineProperty(CodeMirrorWidget.prototype, "editor", { /** * Get the editor wrapped by the widget. * * #### Notes * This is a ready-only property. */ get: function () { return this._editor; }, enumerable: true, configurable: true }); /** * A message handler invoked on an `'after-attach'` message. */ CodeMirrorWidget.prototype.onAfterAttach = function (msg) { if (!this.isVisible) { this._needsRefresh = true; return; } this._editor.refresh(); this._needsRefresh = false; }; /** * A message handler invoked on an `'after-show'` message. */ CodeMirrorWidget.prototype.onAfterShow = function (msg) { if (this._needsRefresh) { this._editor.refresh(); this._needsRefresh = false; } }; /** * A message handler invoked on an `'resize'` message. */ CodeMirrorWidget.prototype.onResize = function (msg) { if (msg.width < 0 || msg.height < 0) { this._editor.refresh(); } else { this._editor.setSize(msg.width, msg.height); } this._needsRefresh = false; }; return CodeMirrorWidget; }(phosphor_widget_1.Widget)); exports.CodeMirrorWidget = CodeMirrorWidget;