@@ -8,13 +8,13 @@ import * as vscode from 'vscode';
8
8
class CopyPasteEditProvider implements vscode . DocumentPasteEditProvider {
9
9
10
10
async provideDocumentPasteEdits (
11
- _document : vscode . TextDocument ,
11
+ document : vscode . TextDocument ,
12
12
_ranges : readonly vscode . Range [ ] ,
13
13
dataTransfer : vscode . DataTransfer ,
14
14
_token : vscode . CancellationToken
15
15
) : Promise < vscode . DocumentPasteEdit | undefined > {
16
16
17
- const enabled = vscode . workspace . getConfiguration ( 'ipynb' , _document ) . get ( 'experimental.pasteImages.enabled' , false ) ;
17
+ const enabled = vscode . workspace . getConfiguration ( 'ipynb' , document ) . get ( 'experimental.pasteImages.enabled' , false ) ;
18
18
if ( ! enabled ) {
19
19
return undefined ;
20
20
}
@@ -42,24 +42,13 @@ class CopyPasteEditProvider implements vscode.DocumentPasteEditProvider {
42
42
return undefined ;
43
43
}
44
44
45
- // get notebook cell
46
- let notebookUri ;
47
- let currentCell ;
48
- for ( const notebook of vscode . workspace . notebookDocuments ) {
49
- if ( notebook . uri . path === _document . uri . path ) {
50
- for ( const cell of notebook . getCells ( ) ) {
51
- if ( cell . document === _document ) {
52
- currentCell = cell ;
53
- notebookUri = notebook . uri ;
54
- break ;
55
- }
56
- }
57
- }
58
- }
59
- if ( ! currentCell || ! notebookUri ) {
45
+ const currentCell = this . getCellFromCellDocument ( document ) ;
46
+ if ( ! currentCell ) {
60
47
return undefined ;
61
48
}
62
49
50
+ const notebookUri = currentCell . notebook . uri ;
51
+
63
52
// create updated metadata for cell (prep for WorkspaceEdit)
64
53
const b64string = encodeBase64 ( fileDataAsUint8 ) ;
65
54
const startingAttachments = currentCell . metadata . custom ?. attachments ;
@@ -78,6 +67,19 @@ class CopyPasteEditProvider implements vscode.DocumentPasteEditProvider {
78
67
79
68
return { insertText : pasteSnippet , additionalEdit : workspaceEdit } ;
80
69
}
70
+
71
+ private getCellFromCellDocument ( cellDocument : vscode . TextDocument ) : vscode . NotebookCell | undefined {
72
+ for ( const notebook of vscode . workspace . notebookDocuments ) {
73
+ if ( notebook . uri . path === cellDocument . uri . path ) {
74
+ for ( const cell of notebook . getCells ( ) ) {
75
+ if ( cell . document === cellDocument ) {
76
+ return cell ;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ return undefined ;
82
+ }
81
83
}
82
84
83
85
/**
0 commit comments