Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7be726fd
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7be726fd
编写于
5月 27, 2020
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support downloading blob URLs and data URLs when clicked in a notebook webview
Fix #98101
上级
0780b5ef
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
4 deletion
+83
-4
src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts
...ntrib/notebook/browser/view/renderers/backLayerWebView.ts
+38
-2
src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts
...s/workbench/contrib/webview/browser/baseWebviewElement.ts
+10
-2
src/vs/workbench/contrib/webview/browser/pre/main.js
src/vs/workbench/contrib/webview/browser/pre/main.js
+29
-0
src/vs/workbench/contrib/webview/browser/webview.ts
src/vs/workbench/contrib/webview/browser/webview.ts
+6
-0
未找到文件。
src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts
浏览文件 @
7be726fd
...
...
@@ -18,12 +18,15 @@ import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookB
import
{
CodeCellViewModel
}
from
'
vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel
'
;
import
{
IProcessedOutput
}
from
'
vs/workbench/contrib/notebook/common/notebookCommon
'
;
import
{
INotebookService
}
from
'
vs/workbench/contrib/notebook/common/notebookService
'
;
import
{
IWebviewService
,
WebviewElement
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
IWebviewService
,
WebviewElement
,
IDataLinkClickEvent
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
asWebviewUri
}
from
'
vs/workbench/contrib/webview/common/webviewUri
'
;
import
{
IWorkbenchEnvironmentService
}
from
'
vs/workbench/services/environment/common/environmentService
'
;
import
{
dirname
}
from
'
vs/base/common/resources
'
;
import
{
dirname
,
joinPath
}
from
'
vs/base/common/resources
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
IFileDialogService
}
from
'
vs/platform/dialogs/common/dialogs
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
export
interface
WebviewIntialized
{
__vscode_notebook_message
:
boolean
;
...
...
@@ -160,6 +163,8 @@ export class BackLayerWebView extends Disposable {
@
IEnvironmentService
private
readonly
environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
readonly
contextService
:
IWorkspaceContextService
,
@
IWorkbenchEnvironmentService
private
readonly
workbenchEnvironmentService
:
IWorkbenchEnvironmentService
,
@
IFileDialogService
private
readonly
fileDialogService
:
IFileDialogService
,
@
IFileService
private
readonly
fileService
:
IFileService
,
)
{
super
();
this
.
element
=
document
.
createElement
(
'
div
'
);
...
...
@@ -516,6 +521,10 @@ ${loaderJs}
}
}));
this
.
_register
(
this
.
webview
.
onDidClickDataLink
(
event
=>
{
this
.
_onDidClickDataLink
(
event
);
}));
this
.
_register
(
this
.
webview
.
onDidReload
(()
=>
{
this
.
preloadsCache
.
clear
();
for
(
const
[
output
,
inset
]
of
this
.
insetMapping
.
entries
())
{
...
...
@@ -586,6 +595,33 @@ ${loaderJs}
}));
}
private
async
_onDidClickDataLink
(
event
:
IDataLinkClickEvent
):
Promise
<
void
>
{
const
defaultDir
=
dirname
(
this
.
documentUri
);
const
defaultUri
=
joinPath
(
defaultDir
,
event
.
downloadName
||
'
download.png
'
);
const
newFileUri
=
await
this
.
fileDialogService
.
showSaveDialog
({
defaultUri
});
if
(
!
newFileUri
)
{
return
;
}
const
splitData
=
event
.
dataURL
.
split
(
'
;base64,
'
)[
1
];
if
(
!
splitData
)
{
return
;
}
const
decoded
=
atob
(
splitData
);
const
typedArray
=
new
Uint8Array
(
decoded
.
length
);
for
(
let
i
=
0
;
i
<
decoded
.
length
;
i
++
)
{
typedArray
[
i
]
=
decoded
.
charCodeAt
(
i
);
}
const
buff
=
VSBuffer
.
wrap
(
typedArray
);
await
this
.
fileService
.
writeFile
(
newFileUri
,
buff
);
await
this
.
openerService
.
open
(
newFileUri
);
}
async
waitForInitialization
()
{
await
this
.
_initalized
;
}
...
...
src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts
浏览文件 @
7be726fd
...
...
@@ -6,12 +6,12 @@
import
{
addClass
}
from
'
vs/base/browser/dom
'
;
import
{
IMouseWheelEvent
}
from
'
vs/base/browser/mouseEvent
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
ExtensionIdentifier
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
WebviewExtensionDescription
,
WebviewOptions
,
WebviewContent
Options
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
IDataLinkClickEvent
,
WebviewContentOptions
,
WebviewExtensionDescription
,
Webview
Options
}
from
'
vs/workbench/contrib/webview/browser/webview
'
;
import
{
areWebviewInputOptionsEqual
}
from
'
vs/workbench/contrib/webview/browser/webviewWorkbenchService
'
;
import
{
WebviewThemeDataProvider
}
from
'
vs/workbench/contrib/webview/common/themeing
'
;
import
{
IWorkbenchEnvironmentService
}
from
'
vs/workbench/services/environment/common/environmentService
'
;
...
...
@@ -26,6 +26,7 @@ export const enum WebviewMessageChannels {
doUpdateState
=
'
do-update-state
'
,
doReload
=
'
do-reload
'
,
loadResource
=
'
load-resource
'
,
saveResource
=
'
save-resource
'
,
loadLocalhost
=
'
load-localhost
'
,
webviewReady
=
'
webview-ready
'
,
wheel
=
'
did-scroll-wheel
'
...
...
@@ -136,6 +137,10 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
this
.
handleKeyDown
(
data
);
}));
this
.
_register
(
this
.
on
(
WebviewMessageChannels
.
saveResource
,
(
event
:
IDataLinkClickEvent
)
=>
{
this
.
_onDidClickDataLink
.
fire
(
event
);
}));
this
.
style
();
this
.
_register
(
webviewThemeDataProvider
.
onThemeDataChanged
(
this
.
style
,
this
));
}
...
...
@@ -155,6 +160,9 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
private
readonly
_onDidClickLink
=
this
.
_register
(
new
Emitter
<
string
>
());
public
readonly
onDidClickLink
=
this
.
_onDidClickLink
.
event
;
private
readonly
_onDidClickDataLink
=
this
.
_register
(
new
Emitter
<
IDataLinkClickEvent
>
());
public
readonly
onDidClickDataLink
=
this
.
_onDidClickDataLink
.
event
;
private
readonly
_onDidReload
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidReload
=
this
.
_onDidReload
.
event
;
...
...
src/vs/workbench/contrib/webview/browser/pre/main.js
浏览文件 @
7be726fd
...
...
@@ -240,6 +240,10 @@
if
(
scrollTarget
)
{
scrollTarget
.
scrollIntoView
();
}
}
else
if
(
node
.
href
.
startsWith
(
'
blob:
'
))
{
handleBlobUrlClick
(
node
.
href
,
node
.
download
);
}
else
if
(
node
.
href
.
startsWith
(
'
data:
'
))
{
handleDataUrlClick
(
node
.
href
,
node
.
download
);
}
else
{
host
.
postMessage
(
'
did-click-link
'
,
node
.
href
.
baseVal
||
node
.
href
);
}
...
...
@@ -250,6 +254,31 @@
}
};
const
handleDataUrlClick
=
async
(
url
,
downloadName
)
=>
{
host
.
postMessage
(
'
save-resource
'
,
{
data
:
url
,
downloadName
});
};
const
handleBlobUrlClick
=
async
(
url
,
downloadName
)
=>
{
try
{
const
response
=
await
fetch
(
url
);
const
blob
=
await
response
.
blob
();
const
reader
=
new
FileReader
();
reader
.
addEventListener
(
'
load
'
,
()
=>
{
const
data
=
reader
.
result
;
host
.
postMessage
(
'
save-resource
'
,
{
data
,
downloadName
});
});
reader
.
readAsDataURL
(
blob
);
}
catch
(
e
)
{
console
.
error
(
e
.
message
);
}
};
/**
* @param {MouseEvent} event
*/
...
...
src/vs/workbench/contrib/webview/browser/webview.ts
浏览文件 @
7be726fd
...
...
@@ -73,6 +73,11 @@ export interface WebviewExtensionDescription {
readonly
id
:
ExtensionIdentifier
;
}
export
interface
IDataLinkClickEvent
{
dataURL
:
string
;
downloadName
?:
string
;
}
export
interface
Webview
extends
IDisposable
{
html
:
string
;
contentOptions
:
WebviewContentOptions
;
...
...
@@ -84,6 +89,7 @@ export interface Webview extends IDisposable {
readonly
onDidFocus
:
Event
<
void
>
;
readonly
onDidBlur
:
Event
<
void
>
;
readonly
onDidClickLink
:
Event
<
string
>
;
readonly
onDidClickDataLink
:
Event
<
IDataLinkClickEvent
>
;
readonly
onDidScroll
:
Event
<
{
scrollYPercentage
:
number
}
>
;
readonly
onDidWheel
:
Event
<
IMouseWheelEvent
>
;
readonly
onDidUpdateState
:
Event
<
string
|
undefined
>
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录