@@ -49,8 +49,8 @@ const textPlain = 'text/plain';
49
49
const str = await existing . asString ( ) ;
50
50
// text/plain includes the trailing new line in this case
51
51
// On windows, this will always be `\r\n` even if the document uses `\n`
52
- const eol = str . match ( / \r ? \n $ / ) ;
53
- const reversed = reverseString ( str . slice ( 0 , - eol ! [ 0 ] . length ) ) ;
52
+ const eol = str . match ( / \r ? \n $ / ) ?. [ 0 ] ?? '\n' ;
53
+ const reversed = reverseString ( str . slice ( 0 , - eol . length ) ) ;
54
54
dataTransfer . set ( textPlain , new vscode . DataTransferItem ( reversed + '\n' ) ) ;
55
55
}
56
56
}
@@ -170,7 +170,32 @@ const textPlain = 'text/plain';
170
170
const newDocContent = getNextDocumentText ( disposables , doc ) ;
171
171
await vscode . commands . executeCommand ( 'editor.action.clipboardPasteAction' ) ;
172
172
assert . strictEqual ( await newDocContent , 'cba\ndef' ) ;
173
+ } ) ) ;
174
+
175
+
176
+ test ( 'One failing provider should not effect other' , usingDisposables ( async ( disposables ) => {
177
+ const file = await createRandomFile ( 'abc\ndef' ) ;
178
+ const doc = await vscode . workspace . openTextDocument ( file ) ;
179
+
180
+ const editor = await vscode . window . showTextDocument ( doc ) ;
181
+ editor . selections = [ new vscode . Selection ( 0 , 0 , 0 , 3 ) ] ;
182
+
183
+ disposables . push ( vscode . languages . registerDocumentPasteEditProvider ( { language : 'plaintext' } , new class implements vscode . DocumentPasteEditProvider {
184
+ async prepareDocumentPaste ( _document : vscode . TextDocument , _ranges : readonly vscode . Range [ ] , dataTransfer : vscode . DataTransfer , _token : vscode . CancellationToken ) : Promise < void > {
185
+ dataTransfer . set ( textPlain , new vscode . DataTransferItem ( 'xyz' ) ) ;
186
+ }
187
+ } , { copyMimeTypes : [ textPlain ] } ) ) ;
173
188
189
+ disposables . push ( vscode . languages . registerDocumentPasteEditProvider ( { language : 'plaintext' } , new class implements vscode . DocumentPasteEditProvider {
190
+ async prepareDocumentPaste ( _document : vscode . TextDocument , _ranges : readonly vscode . Range [ ] , _dataTransfer : vscode . DataTransfer , _token : vscode . CancellationToken ) : Promise < void > {
191
+ throw new Error ( 'Expected testing error from bad provider' ) ;
192
+ }
193
+ } , { copyMimeTypes : [ textPlain ] } ) ) ;
194
+
195
+ await vscode . commands . executeCommand ( 'editor.action.clipboardCopyAction' ) ;
196
+ const newDocContent = getNextDocumentText ( disposables , doc ) ;
197
+ await vscode . commands . executeCommand ( 'editor.action.clipboardPasteAction' ) ;
198
+ assert . strictEqual ( await newDocContent , 'xyz\ndef' ) ;
174
199
} ) ) ;
175
200
} ) ;
176
201
@@ -181,10 +206,9 @@ function reverseString(str: string) {
181
206
function getNextDocumentText ( disposables : vscode . Disposable [ ] , doc : vscode . TextDocument ) : Promise < string > {
182
207
return new Promise < string > ( resolve => {
183
208
disposables . push ( vscode . workspace . onDidChangeTextDocument ( e => {
184
- if ( e . document === doc ) {
185
- resolve ( doc . getText ( ) ) ;
209
+ if ( e . document . uri . fsPath === doc . uri . fsPath ) {
210
+ resolve ( e . document . getText ( ) ) ;
186
211
}
187
212
} ) ) ;
188
213
} ) ;
189
214
}
190
-
0 commit comments