Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8e475f9b
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
8e475f9b
编写于
12月 16, 2019
作者:
M
Matt Bierner
提交者:
GitHub
12月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement draft 2 from #86802 (#87117)
上级
d117af09
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
115 addition
and
156 deletion
+115
-156
extensions/image-preview/src/extension.ts
extensions/image-preview/src/extension.ts
+1
-1
extensions/image-preview/src/preview.ts
extensions/image-preview/src/preview.ts
+4
-6
extensions/markdown-language-features/src/features/previewManager.ts
...markdown-language-features/src/features/previewManager.ts
+5
-6
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+36
-50
src/vs/workbench/api/browser/mainThreadWebview.ts
src/vs/workbench/api/browser/mainThreadWebview.ts
+28
-24
src/vs/workbench/api/common/extHost.api.impl.ts
src/vs/workbench/api/common/extHost.api.impl.ts
+2
-2
src/vs/workbench/api/common/extHost.protocol.ts
src/vs/workbench/api/common/extHost.protocol.ts
+7
-8
src/vs/workbench/api/common/extHostWebview.ts
src/vs/workbench/api/common/extHostWebview.ts
+30
-57
src/vs/workbench/contrib/customEditor/common/customEditor.ts
src/vs/workbench/contrib/customEditor/common/customEditor.ts
+1
-1
src/vs/workbench/contrib/customEditor/common/customEditorModel.ts
...orkbench/contrib/customEditor/common/customEditorModel.ts
+1
-1
未找到文件。
extensions/image-preview/src/extension.ts
浏览文件 @
8e475f9b
...
...
@@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
const
previewManager
=
new
PreviewManager
(
extensionRoot
,
sizeStatusBarEntry
,
binarySizeStatusBarEntry
,
zoomStatusBarEntry
);
context
.
subscriptions
.
push
(
vscode
.
window
.
registerWebviewEditorProvider
(
PreviewManager
.
viewType
,
previewManager
));
context
.
subscriptions
.
push
(
vscode
.
window
.
registerWebview
Custom
EditorProvider
(
PreviewManager
.
viewType
,
previewManager
));
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
imagePreview.zoomIn
'
,
()
=>
{
previewManager
.
activePreview
?.
zoomIn
();
...
...
extensions/image-preview/src/preview.ts
浏览文件 @
8e475f9b
...
...
@@ -13,7 +13,7 @@ import { BinarySizeStatusBarEntry } from './binarySizeStatusBarEntry';
const
localize
=
nls
.
loadMessageBundle
();
export
class
PreviewManager
implements
vscode
.
WebviewEditorProvider
{
export
class
PreviewManager
implements
vscode
.
Webview
Custom
EditorProvider
{
public
static
readonly
viewType
=
'
imagePreview.previewEditor
'
;
...
...
@@ -28,10 +28,10 @@ export class PreviewManager implements vscode.WebviewEditorProvider {
)
{
}
public
async
resolveWebviewEditor
(
input
:
{
readonly
resource
:
vscode
.
Uri
,
}
,
resource
:
vscode
.
Uri
,
webviewEditor
:
vscode
.
WebviewPanel
,
):
Promise
<
v
scode
.
WebviewEditorCapabilities
>
{
const
preview
=
new
Preview
(
this
.
extensionRoot
,
input
.
resource
,
webviewEditor
,
this
.
sizeStatusBarEntry
,
this
.
binarySizeStatusBarEntry
,
this
.
zoomStatusBarEntry
);
):
Promise
<
v
oid
>
{
const
preview
=
new
Preview
(
this
.
extensionRoot
,
resource
,
webviewEditor
,
this
.
sizeStatusBarEntry
,
this
.
binarySizeStatusBarEntry
,
this
.
zoomStatusBarEntry
);
this
.
_previews
.
add
(
preview
);
this
.
setActivePreview
(
preview
);
...
...
@@ -44,8 +44,6 @@ export class PreviewManager implements vscode.WebviewEditorProvider {
this
.
setActivePreview
(
undefined
);
}
});
return
{};
}
public
get
activePreview
()
{
return
this
.
_activePreview
;
}
...
...
extensions/markdown-language-features/src/features/previewManager.ts
浏览文件 @
8e475f9b
...
...
@@ -52,7 +52,7 @@ class PreviewStore extends Disposable {
}
}
export
class
MarkdownPreviewManager
extends
Disposable
implements
vscode
.
WebviewPanelSerializer
,
vscode
.
WebviewEditorProvider
{
export
class
MarkdownPreviewManager
extends
Disposable
implements
vscode
.
WebviewPanelSerializer
,
vscode
.
Webview
Custom
EditorProvider
{
private
static
readonly
markdownPreviewActiveContextKey
=
'
markdownPreviewFocus
'
;
private
readonly
_topmostLineMonitor
=
new
TopmostLineMonitor
();
...
...
@@ -70,7 +70,7 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
)
{
super
();
this
.
_register
(
vscode
.
window
.
registerWebviewPanelSerializer
(
DynamicMarkdownPreview
.
viewType
,
this
));
this
.
_register
(
vscode
.
window
.
registerWebviewEditorProvider
(
'
vscode.markdown.preview.editor
'
,
this
));
this
.
_register
(
vscode
.
window
.
registerWebview
Custom
EditorProvider
(
'
vscode.markdown.preview.editor
'
,
this
));
}
public
refresh
()
{
...
...
@@ -149,11 +149,11 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
}
public
async
resolveWebviewEditor
(
input
:
{
readonly
resource
:
vscode
.
Uri
;
}
,
resource
:
vscode
.
Uri
,
webview
:
vscode
.
WebviewPanel
):
Promise
<
v
scode
.
WebviewEditorCapabilities
>
{
):
Promise
<
v
oid
>
{
const
preview
=
DynamicMarkdownPreview
.
revive
(
{
resource
:
input
.
resource
,
locked
:
false
,
resourceColumn
:
vscode
.
ViewColumn
.
One
},
{
resource
,
locked
:
false
,
resourceColumn
:
vscode
.
ViewColumn
.
One
},
webview
,
this
.
_contentProvider
,
this
.
_previewConfigurations
,
...
...
@@ -161,7 +161,6 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
this
.
_topmostLineMonitor
,
this
.
_contributions
);
this
.
registerStaticPreview
(
preview
);
return
{};
}
private
createNewDynamicPreview
(
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
8e475f9b
...
...
@@ -1180,101 +1180,87 @@ declare module 'vscode' {
//#region Custom editors: https://github.com/microsoft/vscode/issues/77131
/**
* Defines how a webview editor interacts with VS Code.
*/
interface
WebviewEditorCapabilities
{
/**
* Invoked when the resource has been renamed in VS Code.
*
* This is called when the resource's new name also matches the custom editor selector.
*
* If this is not implemented—or if the new resource name does not match the existing selector—then VS Code
* will close and reopen the editor on rename.
*
* @param newResource Full path to the resource.
*
* @return Thenable that signals the save is complete.
*/
// rename?(newResource: Uri): Thenable<void>;
/**
* Controls the editing functionality of a webview editor. This allows the webview editor to hook into standard
* editor events such as `undo` or `save`.
*
* WebviewEditors that do not have `editingCapability` are considered to be readonly. Users can still interact
* with readonly editors, but these editors will not integrate with VS Code's standard editor functionality.
*/
readonly
editingCapability
?:
WebviewEditorEditingCapability
;
}
/**
* Defines the editing functionality of a webview editor. This allows the webview editor to hook into standard
* editor events such as `undo` or `save`.
*
* @param EditType Type of edits. Edit objects must be json serializable.
*/
interface
Webview
EditorEditingCapability
{
interface
Webview
CustomEditorEditingDelegate
<
EditType
>
{
/**
*
Persist the
resource.
*
Save a
resource.
*
*
Extensions should persist the resource
*
@param resource Resource being saved.
*
* @return Thenable signaling that the save has completed.
*/
save
():
Thenable
<
void
>
;
save
(
resource
:
Uri
):
Thenable
<
void
>
;
/**
* Save an existing resource at a new path.
*
* @param resource Resource being saved.
* @param targetResource Location to save to.
*
* @return Thenable signaling that the save has completed.
*/
saveAs
(
resource
:
Uri
,
targetResource
:
Uri
):
Thenable
<
void
>
;
/**
* Event triggered by extensions to signal to VS Code that an edit has occurred.
*
* The edit must be a json serializable object.
*/
readonly
onEdit
:
Event
<
any
>
;
readonly
onEdit
:
Event
<
{
readonly
resource
:
Uri
,
readonly
edit
:
EditType
}
>
;
/**
* Apply a set of edits.
*
* This is triggered on redo and when restoring a custom editor after restart. Note that is not invoked
* when `onEdit` is called as `onEdit` implies also updating the view to reflect the edit.
* Note that is not invoked when `onEdit` is called as `onEdit` implies also updating the view to reflect the edit.
*
* @param resource Resource being edited.
* @param edit Array of edits. Sorted from oldest to most recent.
*
* @return Thenable signaling that the change has completed.
*/
applyEdits
(
edits
:
readonly
any
[]):
Thenable
<
void
>
;
applyEdits
(
resource
:
Uri
,
edits
:
readonly
EditType
[]):
Thenable
<
void
>
;
/**
* Undo a set of edits.
*
* This is triggered when a user undoes an edit or when revert is called on a file.
*
* @param resource Resource being edited.
* @param edit Array of edits. Sorted from most recent to oldest.
*
* @return Thenable signaling that the change has completed.
*/
undoEdits
(
edits
:
readonly
any
[]):
Thenable
<
void
>
;
undoEdits
(
resource
:
Uri
,
edits
:
readonly
EditType
[]):
Thenable
<
void
>
;
}
export
interface
WebviewEditorProvider
{
export
interface
Webview
Custom
EditorProvider
{
/**
* Resolve a webview editor for a given resource.
*
* To resolve a webview editor, a provider must fill in its initial html content and hook up all
* the event listeners it is interested it. The provider should also take ownership of the passed in `WebviewPanel`.
*
* @param
input Information about the r
esource being resolved.
* @param
resource R
esource being resolved.
* @param webview Webview being resolved. The provider should take ownership of this webview.
*
* @return Thenable to a `WebviewEditorCapabilities` indicating that the webview editor has been resolved.
* The `WebviewEditorCapabilities` defines how the custom editor interacts with VS Code.
* @return Thenable indicating that the webview editor has been resolved.
*/
resolveWebviewEditor
(
input
:
{
readonly
resource
:
Uri
},
resource
:
Uri
,
webview
:
WebviewPanel
,
):
Thenable
<
WebviewEditorCapabilities
>
;
):
Thenable
<
void
>
;
/**
* Controls the editing functionality of a webview editor. This allows the webview editor to hook into standard
* editor events such as `undo` or `save`.
*
* WebviewEditors that do not have `editingCapability` are considered to be readonly. Users can still interact
* with readonly editors, but these editors will not integrate with VS Code's standard editor functionality.
*/
readonly
editingDelegate
?:
WebviewCustomEditorEditingDelegate
<
unknown
>
;
}
namespace
window
{
...
...
@@ -1285,11 +1271,11 @@ declare module 'vscode' {
* @param provider Resolves webview editors.
* @param options Content settings for a webview panels the provider is given.
*
* @return Disposable that unregisters the `WebviewEditorProvider`.
* @return Disposable that unregisters the `Webview
Custom
EditorProvider`.
*/
export
function
registerWebviewEditorProvider
(
export
function
registerWebview
Custom
EditorProvider
(
viewType
:
string
,
provider
:
WebviewEditorProvider
,
provider
:
Webview
Custom
EditorProvider
,
options
?:
WebviewPanelOptions
,
):
Disposable
;
}
...
...
src/vs/workbench/api/browser/mainThreadWebview.ts
浏览文件 @
8e475f9b
...
...
@@ -252,7 +252,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
this
.
_revivers
.
delete
(
viewType
);
}
public
$registerEditorProvider
(
extensionData
:
extHostProtocol
.
WebviewExtensionDescription
,
viewType
:
string
,
options
:
modes
.
IWebviewPanelOptions
):
void
{
public
$registerEditorProvider
(
extensionData
:
extHostProtocol
.
WebviewExtensionDescription
,
viewType
:
string
,
options
:
modes
.
IWebviewPanelOptions
,
capabilities
:
readonly
extHostProtocol
.
WebviewEditorCapabilities
[]
):
void
{
if
(
this
.
_editorProviders
.
has
(
viewType
))
{
throw
new
Error
(
`Provider for
${
viewType
}
already registered`
);
}
...
...
@@ -270,15 +270,17 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
webviewInput
.
webview
.
options
=
options
;
webviewInput
.
webview
.
extension
=
extension
;
const
resource
=
webviewInput
.
getResource
();
const
model
=
await
this
.
getModel
(
webviewInput
);
const
model
=
await
this
.
loadOrCreateModel
(
webviewInput
,
resource
,
viewType
,
capabilities
);
webviewInput
.
onDisposeWebview
(()
=>
{
// TODO: This should be reference counted
this
.
_customEditorService
.
models
.
disposeModel
(
model
);
});
try
{
await
this
.
_proxy
.
$resolveWebviewEditor
(
{
resource
:
webviewInput
.
getResource
(),
edits
:
model
.
currentEdits
}
,
resource
,
handle
,
viewType
,
webviewInput
.
getTitle
(),
...
...
@@ -304,43 +306,45 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
this
.
_editorProviders
.
delete
(
viewType
);
}
public
async
$registerCapabilities
(
handle
:
extHostProtocol
.
WebviewPanelHandle
,
capabilities
:
readonly
extHostProtocol
.
WebviewEditorCapabilities
[]):
Promise
<
void
>
{
const
webviewInput
=
this
.
getWebviewInput
(
handle
);
const
model
=
await
this
.
getModel
(
webviewInput
);
private
async
loadOrCreateModel
(
webviewInput
:
WebviewInput
,
resource
:
URI
,
viewType
:
string
,
capabilities
:
readonly
extHostProtocol
.
WebviewEditorCapabilities
[])
{
const
existingModel
=
this
.
_customEditorService
.
models
.
get
(
webviewInput
.
getResource
(),
webviewInput
.
viewType
);
if
(
existingModel
)
{
return
existingModel
;
}
const
newModel
=
await
this
.
_customEditorService
.
models
.
loadOrCreate
(
webviewInput
.
getResource
(),
webviewInput
.
viewType
);
const
capabilitiesSet
=
new
Set
(
capabilities
);
if
(
capabilitiesSet
.
has
(
extHostProtocol
.
WebviewEditorCapabilities
.
Editable
))
{
model
.
onUndo
(
edits
=>
{
this
.
_proxy
.
$undoEdits
(
handle
,
edits
.
map
(
x
=>
x
.
data
));
});
newModel
.
onUndo
(
edits
=>
{
this
.
_proxy
.
$undoEdits
(
resource
,
viewType
,
edits
.
map
(
x
=>
x
.
data
));
});
m
odel
.
onApplyEdit
(
edits
=>
{
const
editsToApply
=
edits
.
filter
(
x
=>
x
.
source
!==
webviewInput
).
map
(
x
=>
x
.
data
);
newM
odel
.
onApplyEdit
(
edits
=>
{
const
editsToApply
=
edits
.
filter
(
x
=>
x
.
source
!==
newModel
).
map
(
x
=>
x
.
data
);
if
(
editsToApply
.
length
)
{
this
.
_proxy
.
$applyEdits
(
handl
e
,
editsToApply
);
this
.
_proxy
.
$applyEdits
(
resource
,
viewTyp
e
,
editsToApply
);
}
});
model
.
onWillSave
(
e
=>
{
e
.
waitUntil
(
this
.
_proxy
.
$onSave
(
handle
));
});
newModel
.
onWillSave
(
e
=>
{
e
.
waitUntil
(
this
.
_proxy
.
$onSave
(
resource
.
toJSON
(),
viewType
));
});
model
.
onWillSaveAs
(
e
=>
{
e
.
waitUntil
(
this
.
_proxy
.
$onSaveAs
(
handle
,
e
.
resource
.
toJSON
(),
e
.
targetResource
.
toJSON
()));
});
newModel
.
onWillSaveAs
(
e
=>
{
e
.
waitUntil
(
this
.
_proxy
.
$onSaveAs
(
e
.
resource
.
toJSON
(),
viewType
,
e
.
targetResource
.
toJSON
()));
});
}
return
newModel
;
}
private
getModel
(
webviewInput
:
WebviewInput
)
{
return
this
.
_customEditorService
.
models
.
loadOrCreate
(
webviewInput
.
getResource
(),
webviewInput
.
viewType
);
}
public
$onEdit
(
handle
:
extHostProtocol
.
WebviewPanelHandle
,
editData
:
any
):
void
{
const
webview
=
this
.
getWebviewInput
(
handle
);
if
(
!
(
webview
instanceof
CustomFileEditorInput
))
{
throw
new
Error
(
'
Webview is not a webview editor
'
);
}
const
model
=
this
.
_customEditorService
.
models
.
get
(
webview
.
getResource
(),
webview
.
viewType
);
public
$onEdit
(
resource
:
UriComponents
,
viewType
:
string
,
editData
:
any
):
void
{
const
model
=
this
.
_customEditorService
.
models
.
get
(
URI
.
revive
(
resource
),
viewType
);
if
(
!
model
)
{
throw
new
Error
(
'
Could not find model for webview editor
'
);
}
model
.
makeEdit
({
source
:
webview
,
data
:
editData
});
model
.
pushEdit
({
source
:
model
,
data
:
editData
});
}
private
hookupWebviewEventDelegate
(
handle
:
extHostProtocol
.
WebviewPanelHandle
,
input
:
WebviewInput
)
{
...
...
src/vs/workbench/api/common/extHost.api.impl.ts
浏览文件 @
8e475f9b
...
...
@@ -532,9 +532,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
registerWebviewPanelSerializer
:
(
viewType
:
string
,
serializer
:
vscode
.
WebviewPanelSerializer
)
=>
{
return
extHostWebviews
.
registerWebviewPanelSerializer
(
extension
,
viewType
,
serializer
);
},
registerWebview
EditorProvider
:
(
viewType
:
string
,
provider
:
vscode
.
Webview
EditorProvider
,
options
?:
vscode
.
WebviewPanelOptions
)
=>
{
registerWebview
CustomEditorProvider
:
(
viewType
:
string
,
provider
:
vscode
.
WebviewCustom
EditorProvider
,
options
?:
vscode
.
WebviewPanelOptions
)
=>
{
checkProposedApiEnabled
(
extension
);
return
extHostWebviews
.
registerWebviewEditorProvider
(
extension
,
viewType
,
provider
,
options
);
return
extHostWebviews
.
registerWebview
Custom
EditorProvider
(
extension
,
viewType
,
provider
,
options
);
},
registerDecorationProvider
(
provider
:
vscode
.
DecorationProvider
)
{
checkProposedApiEnabled
(
extension
);
...
...
src/vs/workbench/api/common/extHost.protocol.ts
浏览文件 @
8e475f9b
...
...
@@ -572,11 +572,10 @@ export interface MainThreadWebviewsShape extends IDisposable {
$registerSerializer
(
viewType
:
string
):
void
;
$unregisterSerializer
(
viewType
:
string
):
void
;
$registerEditorProvider
(
extension
:
WebviewExtensionDescription
,
viewType
:
string
,
options
:
modes
.
IWebviewPanelOptions
):
void
;
$registerEditorProvider
(
extension
:
WebviewExtensionDescription
,
viewType
:
string
,
options
:
modes
.
IWebviewPanelOptions
,
capabilities
:
readonly
WebviewEditorCapabilities
[]
):
void
;
$unregisterEditorProvider
(
viewType
:
string
):
void
;
$registerCapabilities
(
handle
:
WebviewPanelHandle
,
capabilities
:
readonly
WebviewEditorCapabilities
[]):
void
;
$onEdit
(
handle
:
WebviewPanelHandle
,
editJson
:
any
):
void
;
$onEdit
(
resource
:
UriComponents
,
viewType
:
string
,
editJson
:
any
):
void
;
}
export
interface
WebviewPanelViewStateData
{
...
...
@@ -594,13 +593,13 @@ export interface ExtHostWebviewsShape {
$onDidDisposeWebviewPanel
(
handle
:
WebviewPanelHandle
):
Promise
<
void
>
;
$deserializeWebviewPanel
(
newWebviewHandle
:
WebviewPanelHandle
,
viewType
:
string
,
title
:
string
,
state
:
any
,
position
:
EditorViewColumn
,
options
:
modes
.
IWebviewOptions
&
modes
.
IWebviewPanelOptions
):
Promise
<
void
>
;
$resolveWebviewEditor
(
input
:
{
resource
:
UriComponents
,
edits
:
readonly
any
[]
}
,
newWebviewHandle
:
WebviewPanelHandle
,
viewType
:
string
,
title
:
string
,
position
:
EditorViewColumn
,
options
:
modes
.
IWebviewOptions
&
modes
.
IWebviewPanelOptions
):
Promise
<
void
>
;
$resolveWebviewEditor
(
resource
:
UriComponents
,
newWebviewHandle
:
WebviewPanelHandle
,
viewType
:
string
,
title
:
string
,
position
:
EditorViewColumn
,
options
:
modes
.
IWebviewOptions
&
modes
.
IWebviewPanelOptions
):
Promise
<
void
>
;
$undoEdits
(
handle
:
WebviewPanelHandle
,
edits
:
readonly
any
[]):
void
;
$applyEdits
(
handle
:
WebviewPanelHandle
,
edits
:
readonly
any
[]):
void
;
$undoEdits
(
resource
:
UriComponents
,
viewType
:
string
,
edits
:
readonly
any
[]):
void
;
$applyEdits
(
resource
:
UriComponents
,
viewType
:
string
,
edits
:
readonly
any
[]):
void
;
$onSave
(
handle
:
WebviewPanelHandle
):
Promise
<
void
>
;
$onSaveAs
(
handle
:
WebviewPanelHandle
,
resource
:
UriComponents
,
targetResource
:
UriComponents
):
Promise
<
void
>
;
$onSave
(
resource
:
UriComponents
,
viewType
:
string
):
Promise
<
void
>
;
$onSaveAs
(
resource
:
UriComponents
,
viewType
:
string
,
targetResource
:
UriComponents
):
Promise
<
void
>
;
}
export
interface
MainThreadUrlsShape
extends
IDisposable
{
...
...
src/vs/workbench/api/common/extHostWebview.ts
浏览文件 @
8e475f9b
...
...
@@ -5,7 +5,6 @@
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
assertIsDefined
}
from
'
vs/base/common/types
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
generateUuid
}
from
'
vs/base/common/uuid
'
;
import
*
as
modes
from
'
vs/editor/common/modes
'
;
...
...
@@ -16,7 +15,7 @@ import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
import
{
EditorViewColumn
}
from
'
vs/workbench/api/common/shared/editor
'
;
import
{
asWebviewUri
,
WebviewInitData
}
from
'
vs/workbench/api/common/shared/webview
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
ExtHostWebviewsShape
,
IMainContext
,
MainContext
,
MainThreadWebviewsShape
,
Webview
PanelHandle
,
WebviewPanelViewStateData
,
WebviewEditorCapabilities
}
from
'
./extHost.protocol
'
;
import
{
ExtHostWebviewsShape
,
IMainContext
,
MainContext
,
MainThreadWebviewsShape
,
Webview
EditorCapabilities
,
WebviewPanelHandle
,
WebviewPanelViewStateData
}
from
'
./extHost.protocol
'
;
import
{
Disposable
as
VSCodeDisposable
}
from
'
./extHostTypes
'
;
type
IconPath
=
URI
|
{
light
:
URI
,
dark
:
URI
};
...
...
@@ -117,8 +116,6 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
readonly
_onDidChangeViewStateEmitter
=
this
.
_register
(
new
Emitter
<
vscode
.
WebviewPanelOnDidChangeViewStateEvent
>
());
public
readonly
onDidChangeViewState
:
Event
<
vscode
.
WebviewPanelOnDidChangeViewStateEvent
>
=
this
.
_onDidChangeViewStateEmitter
.
event
;
public
_capabilities
?:
vscode
.
WebviewEditorCapabilities
;
constructor
(
handle
:
WebviewPanelHandle
,
proxy
:
MainThreadWebviewsShape
,
...
...
@@ -239,31 +236,6 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa
});
}
_setCapabilities
(
capabilities
:
vscode
.
WebviewEditorCapabilities
)
{
this
.
_capabilities
=
capabilities
;
if
(
capabilities
.
editingCapability
)
{
this
.
_register
(
capabilities
.
editingCapability
.
onEdit
(
edit
=>
{
this
.
_proxy
.
$onEdit
(
this
.
_handle
,
edit
);
}));
}
}
_undoEdits
(
edits
:
readonly
any
[]):
void
{
assertIsDefined
(
this
.
_capabilities
).
editingCapability
?.
undoEdits
(
edits
);
}
_redoEdits
(
edits
:
readonly
any
[]):
void
{
assertIsDefined
(
this
.
_capabilities
).
editingCapability
?.
applyEdits
(
edits
);
}
async
_onSave
():
Promise
<
void
>
{
await
assertIsDefined
(
this
.
_capabilities
?.
editingCapability
)?.
save
();
}
async
_onSaveAs
(
resource
:
vscode
.
Uri
,
targetResource
:
vscode
.
Uri
):
Promise
<
void
>
{
await
assertIsDefined
(
this
.
_capabilities
?.
editingCapability
)?.
saveAs
(
resource
,
targetResource
);
}
private
assertNotDisposed
()
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
Webview is disposed
'
);
...
...
@@ -280,7 +252,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
private
readonly
_proxy
:
MainThreadWebviewsShape
;
private
readonly
_webviewPanels
=
new
Map
<
WebviewPanelHandle
,
ExtHostWebviewEditor
>
();
private
readonly
_serializers
=
new
Map
<
string
,
{
readonly
serializer
:
vscode
.
WebviewPanelSerializer
,
readonly
extension
:
IExtensionDescription
}
>
();
private
readonly
_editorProviders
=
new
Map
<
string
,
{
readonly
provider
:
vscode
.
WebviewEditorProvider
,
readonly
extension
:
IExtensionDescription
}
>
();
private
readonly
_editorProviders
=
new
Map
<
string
,
{
readonly
provider
:
vscode
.
Webview
Custom
EditorProvider
,
readonly
extension
:
IExtensionDescription
}
>
();
constructor
(
mainContext
:
IMainContext
,
...
...
@@ -331,10 +303,10 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
});
}
public
registerWebviewEditorProvider
(
public
registerWebview
Custom
EditorProvider
(
extension
:
IExtensionDescription
,
viewType
:
string
,
provider
:
vscode
.
WebviewEditorProvider
,
provider
:
vscode
.
Webview
Custom
EditorProvider
,
options
?:
vscode
.
WebviewPanelOptions
,
):
vscode
.
Disposable
{
if
(
this
.
_editorProviders
.
has
(
viewType
))
{
...
...
@@ -342,7 +314,10 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
this
.
_editorProviders
.
set
(
viewType
,
{
extension
,
provider
,
});
this
.
_proxy
.
$registerEditorProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
,
options
||
{});
this
.
_proxy
.
$registerEditorProvider
({
id
:
extension
.
identifier
,
location
:
extension
.
extensionLocation
},
viewType
,
options
||
{},
this
.
getCapabilites
(
provider
));
provider
?.
editingDelegate
?.
onEdit
(({
edit
,
resource
})
=>
{
this
.
_proxy
.
$onEdit
(
resource
,
viewType
,
edit
);
});
return
new
VSCodeDisposable
(()
=>
{
this
.
_editorProviders
.
delete
(
viewType
);
...
...
@@ -431,7 +406,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
async
$resolveWebviewEditor
(
input
:
{
resource
:
UriComponents
,
edits
:
readonly
any
[]
}
,
resource
:
UriComponents
,
handle
:
WebviewPanelHandle
,
viewType
:
string
,
title
:
string
,
...
...
@@ -447,46 +422,44 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
const
webview
=
new
ExtHostWebview
(
handle
,
this
.
_proxy
,
options
,
this
.
initData
,
this
.
workspace
,
extension
,
this
.
_logService
);
const
revivedPanel
=
new
ExtHostWebviewEditor
(
handle
,
this
.
_proxy
,
viewType
,
title
,
typeof
position
===
'
number
'
&&
position
>=
0
?
typeConverters
.
ViewColumn
.
to
(
position
)
:
undefined
,
options
,
webview
);
this
.
_webviewPanels
.
set
(
handle
,
revivedPanel
);
const
capabilities
=
await
provider
.
resolveWebviewEditor
({
resource
:
URI
.
revive
(
input
.
resource
)
},
revivedPanel
);
revivedPanel
.
_setCapabilities
(
capabilities
);
this
.
registerCapabilites
(
handle
,
capabilities
);
// TODO: the first set of edits should likely be passed when resolving
if
(
input
.
edits
.
length
)
{
revivedPanel
.
_redoEdits
(
input
.
edits
);
}
const
revivedResource
=
URI
.
revive
(
resource
);
await
provider
.
resolveWebviewEditor
(
revivedResource
,
revivedPanel
);
}
$undoEdits
(
handle
:
WebviewPanelHandle
,
edits
:
readonly
any
[]):
void
{
const
p
anel
=
this
.
getWebviewPanel
(
handl
e
);
p
anel
?.
_undoEdits
(
edits
);
$undoEdits
(
resource
:
UriComponents
,
viewType
:
string
,
edits
:
readonly
any
[]):
void
{
const
p
rovider
=
this
.
getEditorProvider
(
viewTyp
e
);
p
rovider
?.
editingDelegate
?.
undoEdits
(
URI
.
revive
(
resource
),
edits
);
}
$applyEdits
(
handle
:
WebviewPanelHandle
,
edits
:
readonly
any
[]):
void
{
const
p
anel
=
this
.
getWebviewPanel
(
handl
e
);
p
anel
?.
_redoEdits
(
edits
);
$applyEdits
(
resource
:
UriComponents
,
viewType
:
string
,
edits
:
readonly
any
[]):
void
{
const
p
rovider
=
this
.
getEditorProvider
(
viewTyp
e
);
p
rovider
?.
editingDelegate
?.
applyEdits
(
URI
.
revive
(
resource
),
edits
);
}
async
$onSave
(
handle
:
WebviewPanelHandle
):
Promise
<
void
>
{
const
p
anel
=
this
.
getWebviewPanel
(
handl
e
);
return
p
anel
?.
_onSave
(
);
async
$onSave
(
resource
:
UriComponents
,
viewType
:
string
):
Promise
<
void
>
{
const
p
rovider
=
this
.
getEditorProvider
(
viewTyp
e
);
return
p
rovider
?.
editingDelegate
?.
save
(
URI
.
revive
(
resource
)
);
}
async
$onSaveAs
(
handle
:
WebviewPanelHandle
,
resource
:
UriComponents
,
targetResource
:
UriComponents
):
Promise
<
void
>
{
const
p
anel
=
this
.
getWebviewPanel
(
handl
e
);
return
p
anel
?.
_onS
aveAs
(
URI
.
revive
(
resource
),
URI
.
revive
(
targetResource
));
async
$onSaveAs
(
resource
:
UriComponents
,
viewType
:
string
,
targetResource
:
UriComponents
):
Promise
<
void
>
{
const
p
rovider
=
this
.
getEditorProvider
(
viewTyp
e
);
return
p
rovider
?.
editingDelegate
?.
s
aveAs
(
URI
.
revive
(
resource
),
URI
.
revive
(
targetResource
));
}
private
getWebviewPanel
(
handle
:
WebviewPanelHandle
):
ExtHostWebviewEditor
|
undefined
{
return
this
.
_webviewPanels
.
get
(
handle
);
}
private
registerCapabilites
(
handle
:
WebviewPanelHandle
,
capabilities
:
vscode
.
WebviewEditorCapabilities
)
{
private
getEditorProvider
(
viewType
:
string
):
vscode
.
WebviewCustomEditorProvider
|
undefined
{
return
this
.
_editorProviders
.
get
(
viewType
)?.
provider
;
}
private
getCapabilites
(
capabilities
:
vscode
.
WebviewCustomEditorProvider
)
{
const
declaredCapabilites
:
WebviewEditorCapabilities
[]
=
[];
if
(
capabilities
.
editing
Capability
)
{
if
(
capabilities
.
editing
Delegate
)
{
declaredCapabilites
.
push
(
WebviewEditorCapabilities
.
Editable
);
}
this
.
_proxy
.
$registerCapabilities
(
handle
,
declaredCapabilites
)
;
return
declaredCapabilites
;
}
}
...
...
src/vs/workbench/contrib/customEditor/common/customEditor.ts
浏览文件 @
8e475f9b
...
...
@@ -77,7 +77,7 @@ export interface ICustomEditorModel extends IWorkingCopy {
save
(
options
?:
ISaveOptions
):
Promise
<
boolean
>
;
saveAs
(
resource
:
URI
,
targetResource
:
URI
,
currentOptions
?:
ISaveOptions
):
Promise
<
boolean
>
;
make
Edit
(
edit
:
CustomEditorEdit
):
void
;
push
Edit
(
edit
:
CustomEditorEdit
):
void
;
}
export
const
enum
CustomEditorPriority
{
...
...
src/vs/workbench/contrib/customEditor/common/customEditorModel.ts
浏览文件 @
8e475f9b
...
...
@@ -57,7 +57,7 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel
return
this
.
_edits
.
slice
(
0
,
Math
.
max
(
0
,
this
.
_currentEditIndex
+
1
));
}
public
make
Edit
(
edit
:
CustomEditorEdit
):
void
{
public
push
Edit
(
edit
:
CustomEditorEdit
):
void
{
this
.
_edits
.
splice
(
this
.
_currentEditIndex
+
1
,
this
.
_edits
.
length
-
this
.
_currentEditIndex
,
edit
.
data
);
this
.
_currentEditIndex
=
this
.
_edits
.
length
-
1
;
this
.
updateDirty
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录