5
5
6
6
import { asArray , coalesce , isNonEmptyArray } from 'vs/base/common/arrays' ;
7
7
import { encodeBase64 , VSBuffer } from 'vs/base/common/buffer' ;
8
+ import { IDataTransferItem , UriList , VSDataTransfer } from 'vs/base/common/dataTransfer' ;
9
+ import { once } from 'vs/base/common/functional' ;
8
10
import * as htmlContent from 'vs/base/common/htmlContent' ;
9
11
import { DisposableStore } from 'vs/base/common/lifecycle' ;
10
12
import { ResourceSet } from 'vs/base/common/map' ;
11
13
import { marked } from 'vs/base/common/marked/marked' ;
12
14
import { parse } from 'vs/base/common/marshalling' ;
15
+ import { Mimes } from 'vs/base/common/mime' ;
13
16
import { cloneAndChange } from 'vs/base/common/objects' ;
14
17
import { isEmptyObject , isNumber , isString , isUndefinedOrNull , withNullAsUndefined } from 'vs/base/common/types' ;
15
18
import { URI , UriComponents } from 'vs/base/common/uri' ;
@@ -19,8 +22,8 @@ import { IPosition } from 'vs/editor/common/core/position';
19
22
import * as editorRange from 'vs/editor/common/core/range' ;
20
23
import { ISelection } from 'vs/editor/common/core/selection' ;
21
24
import { IContentDecorationRenderOptions , IDecorationOptions , IDecorationRenderOptions , IThemeDecorationRenderOptions } from 'vs/editor/common/editorCommon' ;
22
- import * as languages from 'vs/editor/common/languages' ;
23
25
import * as encodedTokenAttributes from 'vs/editor/common/encodedTokenAttributes' ;
26
+ import * as languages from 'vs/editor/common/languages' ;
24
27
import * as languageSelector from 'vs/editor/common/languageSelector' ;
25
28
import { EndOfLineSequence , TrackedRangeStickiness } from 'vs/editor/common/model' ;
26
29
import { ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
@@ -39,8 +42,6 @@ import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGro
39
42
import { ACTIVE_GROUP , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
40
43
import type * as vscode from 'vscode' ;
41
44
import * as types from './extHostTypes' ;
42
- import { once } from 'vs/base/common/functional' ;
43
- import { IDataTransferItem , VSDataTransfer } from 'vs/base/common/dataTransfer' ;
44
45
45
46
export namespace Command {
46
47
@@ -1966,7 +1967,7 @@ export namespace ViewBadge {
1966
1967
}
1967
1968
1968
1969
export namespace DataTransferItem {
1969
- export function toDataTransferItem ( item : extHostProtocol . DataTransferItemDTO , resolveFileData : ( ) => Promise < Uint8Array > ) : types . DataTransferItem {
1970
+ export function to ( mime : string , item : extHostProtocol . DataTransferItemDTO , resolveFileData : ( ) => Promise < Uint8Array > ) : types . DataTransferItem {
1970
1971
const file = item . fileData ;
1971
1972
if ( file ) {
1972
1973
return new class extends types . DataTransferItem {
@@ -1978,16 +1979,62 @@ export namespace DataTransferItem {
1978
1979
} ;
1979
1980
}
1980
1981
} ( '' , item . id ) ;
1981
- } else {
1982
- return new types . DataTransferItem ( item . asString ) ;
1983
1982
}
1983
+
1984
+ if ( mime === Mimes . uriList && item . uriListData ) {
1985
+ return new types . DataTransferItem ( reviveUriList ( item . uriListData ) ) ;
1986
+ }
1987
+
1988
+ return new types . DataTransferItem ( item . asString ) ;
1989
+ }
1990
+
1991
+ export async function from ( mime : string , item : vscode . DataTransferItem | IDataTransferItem ) : Promise < extHostProtocol . DataTransferItemDTO > {
1992
+ const stringValue = await item . asString ( ) ;
1993
+
1994
+ if ( mime === Mimes . uriList ) {
1995
+ return {
1996
+ id : ( item as IDataTransferItem | types . DataTransferItem ) . id ,
1997
+ asString : '' ,
1998
+ fileData : undefined ,
1999
+ uriListData : serializeUriList ( stringValue ) ,
2000
+ } ;
2001
+ }
2002
+
2003
+ const fileValue = item . asFile ( ) ;
2004
+ return {
2005
+ id : ( item as IDataTransferItem | types . DataTransferItem ) . id ,
2006
+ asString : stringValue ,
2007
+ fileData : fileValue ? { name : fileValue . name , uri : fileValue . uri } : undefined ,
2008
+ } ;
2009
+ }
2010
+
2011
+ function serializeUriList ( stringValue : string ) : ReadonlyArray < string | URI > {
2012
+ return UriList . split ( stringValue ) . map ( part => {
2013
+ if ( part . startsWith ( '#' ) ) {
2014
+ return part ;
2015
+ }
2016
+
2017
+ try {
2018
+ return URI . parse ( part ) ;
2019
+ } catch {
2020
+ // noop
2021
+ }
2022
+
2023
+ return part ;
2024
+ } ) ;
2025
+ }
2026
+
2027
+ function reviveUriList ( parts : ReadonlyArray < string | UriComponents > ) : string {
2028
+ return UriList . create ( parts . map ( part => {
2029
+ return typeof part === 'string' ? part : URI . revive ( part ) ;
2030
+ } ) ) ;
1984
2031
}
1985
2032
}
1986
2033
1987
2034
export namespace DataTransfer {
1988
2035
export function toDataTransfer ( value : extHostProtocol . DataTransferDTO , resolveFileData : ( itemId : string ) => Promise < Uint8Array > ) : types . DataTransfer {
1989
2036
const init = value . items . map ( ( [ type , item ] ) => {
1990
- return [ type , DataTransferItem . toDataTransferItem ( item , ( ) => resolveFileData ( item . id ) ) ] as const ;
2037
+ return [ type , DataTransferItem . to ( type , item , ( ) => resolveFileData ( item . id ) ) ] as const ;
1991
2038
} ) ;
1992
2039
return new types . DataTransfer ( init ) ;
1993
2040
}
@@ -1999,13 +2046,7 @@ export namespace DataTransfer {
1999
2046
2000
2047
value . forEach ( ( value , key ) => {
2001
2048
promises . push ( ( async ( ) => {
2002
- const stringValue = await value . asString ( ) ;
2003
- const fileValue = value . asFile ( ) ;
2004
- newDTO . items . push ( [ key , {
2005
- id : ( value as IDataTransferItem | types . DataTransferItem ) . id ,
2006
- asString : stringValue ,
2007
- fileData : fileValue ? { name : fileValue . name , uri : fileValue . uri } : undefined ,
2008
- } ] ) ;
2049
+ newDTO . items . push ( [ key , await DataTransferItem . from ( key , value ) ] ) ;
2009
2050
} ) ( ) ) ;
2010
2051
} ) ;
2011
2052
0 commit comments