This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
widget.ts
81 lines (69 loc) · 1.61 KB
/
widget.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
'use strict';
import {
Message
} from 'phosphor-messaging';
import {
IChangedArgs
} from 'phosphor-properties';
import {
ISignal, Signal
} from 'phosphor-signaling';
import {
ResizeMessage, Widget
} from 'phosphor-widget';
import {
PanelLayout
} from 'phosphor-panel';
import {
IInputAreaModel
} from './model';
import {
CodeMirrorWidget, IEditorModel
} from 'jupyter-js-editor';
/**
* An input area widget, which hosts an editor widget.
*/
export
class InputAreaWidget extends Widget {
/**
* Construct an input area widget.
*/
constructor(model: IInputAreaModel) {
super();
this.addClass('jp-InputAreaWidget');
this._model = model;
this.layout = new PanelLayout();
this.updateTextEditor(model.textEditor);
model.stateChanged.connect(this._modelUpdate, this);
}
/**
* Update the text editor model, creating a new text editor
* widget and detaching the old one.
*/
updateTextEditor(editor: IEditorModel) {
let layout = this.layout as PanelLayout;
if (layout.childCount() > 0) {
layout.childAt(0).dispose();
}
layout.addChild(new CodeMirrorWidget(editor));
}
/**
* Change handler for model updates.
*/
private _modelUpdate(sender: IInputAreaModel, args: IChangedArgs<any>) {
switch(args.name) {
case 'textEditor':
this.updateTextEditor(args.newValue);
break;
case 'collapsed':
break;
case 'promptNumber':
break;
case 'executionCount':
break;
}
}
private _model: IInputAreaModel;
}