@@ -36,34 +36,30 @@ export interface IDraggedResource {
36
36
isExternal : boolean ;
37
37
}
38
38
39
- export class DraggedEditorIdentifier {
39
+ interface ISerializedDraggedResource {
40
+ resource : string ;
41
+ }
40
42
41
- constructor ( private _identifier : IEditorIdentifier ) { }
43
+ export class DraggedEditorIdentifier {
42
44
43
- get identifier ( ) : IEditorIdentifier {
44
- return this . _identifier ;
45
- }
45
+ constructor ( public readonly identifier : IEditorIdentifier ) { }
46
46
}
47
47
48
48
export class DraggedEditorGroupIdentifier {
49
49
50
50
constructor ( public readonly identifier : GroupIdentifier ) { }
51
51
}
52
52
53
- export interface IDraggedEditor extends IDraggedResource {
54
- content ?: string ;
53
+ interface IDraggedEditorProps {
54
+ dirtyContent ?: string ;
55
55
encoding ?: string ;
56
56
mode ?: string ;
57
57
options ?: ITextEditorOptions ;
58
58
}
59
59
60
- export interface ISerializedDraggedEditor {
61
- resource : string ;
62
- content ?: string ;
63
- encoding ?: string ;
64
- mode ?: string ;
65
- options ?: ITextEditorOptions ;
66
- }
60
+ export interface IDraggedEditor extends IDraggedResource , IDraggedEditorProps { }
61
+
62
+ export interface ISerializedDraggedEditor extends ISerializedDraggedResource , IDraggedEditorProps { }
67
63
68
64
export const CodeDataTransfers = {
69
65
EDITORS : 'CodeEditors' ,
@@ -85,7 +81,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): Array<ID
85
81
draggedEditors . forEach ( draggedEditor => {
86
82
resources . push ( {
87
83
resource : URI . parse ( draggedEditor . resource ) ,
88
- content : draggedEditor . content ,
84
+ dirtyContent : draggedEditor . dirtyContent ,
89
85
options : draggedEditor . options ,
90
86
encoding : draggedEditor . encoding ,
91
87
mode : draggedEditor . mode ,
@@ -182,13 +178,12 @@ export class ResourcesDropHandler {
182
178
183
179
// Check for special things being dropped
184
180
const isWorkspaceOpening = await this . doHandleDrop ( untitledOrFileResources ) ;
185
-
186
181
if ( isWorkspaceOpening ) {
187
182
return ; // return early if the drop operation resulted in this window changing to a workspace
188
183
}
189
184
190
185
// Add external ones to recently open list unless dropped resource is a workspace
191
- const recentFiles : IRecentFile [ ] = untitledOrFileResources . filter ( d => d . isExternal && d . resource . scheme === Schemas . file ) . map ( d => ( { fileUri : d . resource } ) ) ;
186
+ const recentFiles : IRecentFile [ ] = untitledOrFileResources . filter ( untitledOrFileResource => untitledOrFileResource . isExternal && untitledOrFileResource . resource . scheme === Schemas . file ) . map ( d => ( { fileUri : d . resource } ) ) ;
192
187
if ( recentFiles . length ) {
193
188
this . workspacesService . addRecentlyOpened ( recentFiles ) ;
194
189
}
@@ -215,15 +210,15 @@ export class ResourcesDropHandler {
215
210
private async doHandleDrop ( untitledOrFileResources : Array < IDraggedResource | IDraggedEditor > ) : Promise < boolean > {
216
211
217
212
// Check for dirty editors being dropped
218
- const resourcesWithContent : IDraggedEditor [ ] = untitledOrFileResources . filter ( resource => ! resource . isExternal && ! ! ( resource as IDraggedEditor ) . content ) ;
219
- if ( resourcesWithContent . length > 0 ) {
220
- await Promise . all ( resourcesWithContent . map ( resourceWithContent => this . handleDirtyEditorDrop ( resourceWithContent ) ) ) ;
213
+ const dirtyEditors : IDraggedEditor [ ] = untitledOrFileResources . filter ( untitledOrFileResource => ! untitledOrFileResource . isExternal && typeof ( untitledOrFileResource as IDraggedEditor ) . dirtyContent === 'string' ) ;
214
+ if ( dirtyEditors . length > 0 ) {
215
+ await Promise . all ( dirtyEditors . map ( dirtyEditor => this . handleDirtyEditorDrop ( dirtyEditor ) ) ) ;
221
216
return false ;
222
217
}
223
218
224
219
// Check for workspace file being dropped if we are allowed to do so
225
220
if ( this . options . allowWorkspaceOpen ) {
226
- const externalFileOnDiskResources = untitledOrFileResources . filter ( d => d . isExternal && d . resource . scheme === Schemas . file ) . map ( d => d . resource ) ;
221
+ const externalFileOnDiskResources = untitledOrFileResources . filter ( untitledOrFileResource => untitledOrFileResource . isExternal && untitledOrFileResource . resource . scheme === Schemas . file ) . map ( d => d . resource ) ;
227
222
if ( externalFileOnDiskResources . length > 0 ) {
228
223
return this . handleWorkspaceFileDrop ( externalFileOnDiskResources ) ;
229
224
}
@@ -249,9 +244,9 @@ export class ResourcesDropHandler {
249
244
250
245
// If the dropped editor is dirty with content we simply take that
251
246
// content and turn it into a backup so that it loads the contents
252
- if ( droppedDirtyEditor . content ) {
247
+ if ( typeof droppedDirtyEditor . dirtyContent === 'string' ) {
253
248
try {
254
- await this . backupFileService . backup ( droppedDirtyEditor . resource , stringToSnapshot ( droppedDirtyEditor . content ) ) ;
249
+ await this . backupFileService . backup ( droppedDirtyEditor . resource , stringToSnapshot ( droppedDirtyEditor . dirtyContent ) ) ;
255
250
} catch ( e ) {
256
251
// Ignore error
257
252
}
@@ -331,9 +326,9 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
331
326
}
332
327
333
328
// Resource URLs: allows to drop multiple resources to a target in VS Code (not directories)
334
- const files = sources . filter ( s => ! s . isDirectory ) ;
329
+ const files = sources . filter ( source => ! source . isDirectory ) ;
335
330
if ( files . length ) {
336
- event . dataTransfer . setData ( DataTransfers . RESOURCES , JSON . stringify ( files . map ( f => f . resource . toString ( ) ) ) ) ;
331
+ event . dataTransfer . setData ( DataTransfers . RESOURCES , JSON . stringify ( files . map ( file => file . resource . toString ( ) ) ) ) ;
337
332
}
338
333
339
334
// Editors: enables cross window DND of tabs into the editor area
@@ -380,13 +375,13 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
380
375
381
376
// If the resource is dirty or untitled, send over its content
382
377
// to restore dirty state. Get that from the text model directly
383
- let content : string | undefined = undefined ;
378
+ let dirtyContent : string | undefined = undefined ;
384
379
if ( model ?. isDirty ( ) ) {
385
- content = model . textEditorModel . getValue ( ) ;
380
+ dirtyContent = model . textEditorModel . getValue ( ) ;
386
381
}
387
382
388
383
// Add as dragged editor
389
- draggedEditors . push ( { resource : file . resource . toString ( ) , content , options, encoding, mode } ) ;
384
+ draggedEditors . push ( { resource : file . resource . toString ( ) , dirtyContent , options, encoding, mode } ) ;
390
385
} ) ;
391
386
392
387
if ( draggedEditors . length ) {
0 commit comments