@@ -20,6 +20,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
20
20
private known_editors_ids : Set < string > ;
21
21
22
22
private _language_info : ILanguageInfoMetadata ;
23
+ private type : nbformat . CellType = 'code' ;
23
24
24
25
constructor ( extension : LSPExtension , editor_widget : NotebookPanel ) {
25
26
super ( extension , editor_widget ) ;
@@ -141,6 +142,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
141
142
this . widget . model . cells . changed . connect ( async ( cells , change ) => {
142
143
let cellsAdded : ICellModel [ ] = [ ] ;
143
144
let cellsRemoved : ICellModel [ ] = [ ] ;
145
+ const type = this . type ;
144
146
145
147
if ( change . type === 'set' ) {
146
148
// handling of conversions is important, because the editors get re-used and their handlers inherited,
@@ -152,13 +154,13 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
152
154
// during conversion the cells should not get deleted nor added
153
155
for ( let i = 0 ; i < change . newValues . length ; i ++ ) {
154
156
if (
155
- change . oldValues [ i ] . type === 'code' &&
156
- change . newValues [ i ] . type !== 'code'
157
+ change . oldValues [ i ] . type === type &&
158
+ change . newValues [ i ] . type !== type
157
159
) {
158
160
convertedToMarkdownOrRaw . push ( change . newValues [ i ] ) ;
159
161
} else if (
160
- change . oldValues [ i ] . type !== 'code' &&
161
- change . newValues [ i ] . type === 'code'
162
+ change . oldValues [ i ] . type !== type &&
163
+ change . newValues [ i ] . type === type
162
164
) {
163
165
convertedToCode . push ( change . newValues [ i ] ) ;
164
166
}
@@ -168,7 +170,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
168
170
}
169
171
} else if ( change . type == 'add' ) {
170
172
cellsAdded = change . newValues . filter (
171
- cellModel => cellModel . type === 'code'
173
+ cellModel => cellModel . type === type
172
174
) ;
173
175
}
174
176
// note: editorRemoved is not emitted for removal of cells by change of type 'remove' (but only during cell type conversion)
@@ -256,7 +258,7 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
256
258
}
257
259
258
260
private activeCellChanged ( notebook : Notebook , cell : Cell ) {
259
- if ( cell . model . type !== 'code' ) {
261
+ if ( cell . model . type !== this . type ) {
260
262
return ;
261
263
}
262
264
if ( ! this . known_editors_ids . has ( cell . editor . uuid ) ) {
@@ -272,6 +274,13 @@ export class NotebookAdapter extends WidgetAdapter<NotebookPanel> {
272
274
273
275
context_from_active_document ( ) : ICommandContext | null {
274
276
let cell = this . widget . content . activeCell ;
277
+ if ( cell . model . type !== this . type ) {
278
+ // context will be sought on all cells to verify if the context menu should be visible,
279
+ // thus it is ok to just return null; it seems to stem from the implementation detail
280
+ // upstream, i.e. the markdown cells appear to be created by transforming the code cells
281
+ // but do not quote me on that.
282
+ return null ;
283
+ }
275
284
let editor = cell . editor ;
276
285
let ce_cursor = editor . getCursorPosition ( ) ;
277
286
let cm_cursor = PositionConverter . ce_to_cm ( ce_cursor ) as IEditorPosition ;
0 commit comments