Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ae0796f0
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,发现更多精彩内容 >>
提交
ae0796f0
编写于
11月 20, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
editor - move auto save to its own file (fixes web to start)
上级
1a88e9d1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
103 addition
and
52 deletion
+103
-52
src/vs/workbench/browser/parts/editor/editor.contribution.ts
src/vs/workbench/browser/parts/editor/editor.contribution.ts
+4
-0
src/vs/workbench/browser/parts/editor/editorAutoSave.ts
src/vs/workbench/browser/parts/editor/editorAutoSave.ts
+95
-0
src/vs/workbench/services/editor/browser/editorService.ts
src/vs/workbench/services/editor/browser/editorService.ts
+4
-52
未找到文件。
src/vs/workbench/browser/parts/editor/editor.contribution.ts
浏览文件 @
ae0796f0
...
...
@@ -54,6 +54,7 @@ import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import
{
withNullAsUndefined
}
from
'
vs/base/common/types
'
;
import
{
registerAndGetAmdImageURL
}
from
'
vs/base/common/amd
'
;
import
{
IFilesConfigurationService
}
from
'
vs/workbench/services/filesConfiguration/common/filesConfigurationService
'
;
import
{
EditorAutoSave
}
from
'
vs/workbench/browser/parts/editor/editorAutoSave
'
;
// Register String Editor
Registry
.
as
<
IEditorRegistry
>
(
EditorExtensions
.
Editors
).
registerEditor
(
...
...
@@ -224,6 +225,9 @@ registerEditorContribution(OpenWorkspaceButtonContribution.ID, OpenWorkspaceButt
// Register Editor Status
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
).
registerWorkbenchContribution
(
EditorStatus
,
LifecyclePhase
.
Ready
);
// Register Editor Auto Save
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
).
registerWorkbenchContribution
(
EditorAutoSave
,
LifecyclePhase
.
Ready
);
// Register Status Actions
const
registry
=
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
);
registry
.
registerWorkbenchAction
(
SyncActionDescriptor
.
create
(
ChangeModeAction
,
ChangeModeAction
.
ID
,
ChangeModeAction
.
LABEL
,
{
primary
:
KeyChord
(
KeyMod
.
CtrlCmd
|
KeyCode
.
KEY_K
,
KeyCode
.
KEY_M
)
}),
'
Change Language Mode
'
);
...
...
src/vs/workbench/browser/parts/editor/editorAutoSave.ts
0 → 100644
浏览文件 @
ae0796f0
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IWorkbenchContribution
}
from
'
vs/workbench/common/contributions
'
;
import
{
Disposable
,
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
IFilesConfigurationService
,
AutoSaveMode
}
from
'
vs/workbench/services/filesConfiguration/common/filesConfigurationService
'
;
import
{
IHostService
}
from
'
vs/workbench/services/host/browser/host
'
;
import
{
SaveReason
,
IEditorIdentifier
,
IEditorInput
,
GroupIdentifier
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
ICodeEditor
,
isCodeEditor
,
isDiffEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IEditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
export
class
EditorAutoSave
extends
Disposable
implements
IWorkbenchContribution
{
private
lastActiveEditor
:
IEditorInput
|
null
=
null
;
private
lastActiveGroupId
:
GroupIdentifier
|
null
=
null
;
private
lastActiveEditorControlDisposable
=
this
.
_register
(
new
DisposableStore
());
constructor
(
@
IFilesConfigurationService
private
readonly
filesConfigurationService
:
IFilesConfigurationService
,
@
IHostService
private
readonly
hostService
:
IHostService
,
@
IEditorService
private
readonly
editorService
:
IEditorService
,
@
IEditorGroupsService
private
readonly
editorGroupService
:
IEditorGroupsService
)
{
super
();
this
.
registerListeners
();
}
private
registerListeners
():
void
{
this
.
_register
(
this
.
hostService
.
onDidChangeFocus
(
focused
=>
this
.
onWindowFocusChange
(
focused
)));
this
.
_register
(
this
.
editorService
.
onDidActiveEditorChange
(()
=>
this
.
onDidActiveEditorChange
()));
}
private
onWindowFocusChange
(
focused
:
boolean
):
void
{
if
(
!
focused
)
{
this
.
maybeTriggerAutoSave
(
SaveReason
.
WINDOW_CHANGE
);
}
}
private
onDidActiveEditorChange
():
void
{
// Treat editor change like a focus change for our last active editor if any
if
(
this
.
lastActiveEditor
&&
typeof
this
.
lastActiveGroupId
===
'
number
'
)
{
this
.
maybeTriggerAutoSave
(
SaveReason
.
FOCUS_CHANGE
,
{
groupId
:
this
.
lastActiveGroupId
,
editor
:
this
.
lastActiveEditor
});
}
// Remember as last active
const
activeGroup
=
this
.
editorGroupService
.
activeGroup
;
const
activeEditor
=
this
.
lastActiveEditor
=
activeGroup
.
activeEditor
;
this
.
lastActiveGroupId
=
activeGroup
.
id
;
// Dispose previous active control listeners
this
.
lastActiveEditorControlDisposable
.
clear
();
// Listen to focus changes on control for auto save
if
(
activeGroup
&&
activeEditor
)
{
const
activeTextEditorWidget
=
this
.
editorService
.
activeTextEditorWidget
;
const
controlsToObserve
:
ICodeEditor
[]
=
[];
if
(
isCodeEditor
(
activeTextEditorWidget
))
{
controlsToObserve
.
push
(
activeTextEditorWidget
);
}
else
if
(
isDiffEditor
(
activeTextEditorWidget
))
{
controlsToObserve
.
push
(
activeTextEditorWidget
.
getOriginalEditor
(),
activeTextEditorWidget
.
getModifiedEditor
());
}
controlsToObserve
.
forEach
(
control
=>
this
.
lastActiveEditorControlDisposable
.
add
(
control
.
onDidBlurEditorWidget
(()
=>
{
this
.
maybeTriggerAutoSave
(
SaveReason
.
FOCUS_CHANGE
,
{
groupId
:
activeGroup
.
id
,
editor
:
activeEditor
});
})));
}
}
private
maybeTriggerAutoSave
(
reason
:
SaveReason
,
editorIdentifier
?:
IEditorIdentifier
):
void
{
if
(
editorIdentifier
&&
(
editorIdentifier
.
editor
.
isReadonly
()
||
editorIdentifier
.
editor
.
isUntitled
()))
{
return
;
// no auto save for readonly or untitled editors
}
const
mode
=
this
.
filesConfigurationService
.
getAutoSaveMode
();
// Determine if we need to save all. In case of a window focus change we also save if auto save mode
// is configured to be ON_FOCUS_CHANGE (editor focus change)
if
(
(
reason
===
SaveReason
.
WINDOW_CHANGE
&&
(
mode
===
AutoSaveMode
.
ON_FOCUS_CHANGE
||
mode
===
AutoSaveMode
.
ON_WINDOW_CHANGE
))
||
(
reason
===
SaveReason
.
FOCUS_CHANGE
&&
mode
===
AutoSaveMode
.
ON_FOCUS_CHANGE
)
)
{
if
(
editorIdentifier
)
{
this
.
editorService
.
save
(
editorIdentifier
,
{
reason
});
}
else
{
this
.
editorService
.
saveAll
({
reason
});
}
}
}
}
src/vs/workbench/services/editor/browser/editorService.ts
浏览文件 @
ae0796f0
...
...
@@ -5,7 +5,7 @@
import
{
IInstantiationService
,
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IResourceInput
,
ITextEditorOptions
,
IEditorOptions
,
EditorActivation
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorInput
,
IEditor
,
GroupIdentifier
,
IFileEditorInput
,
IUntitledTextResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditorInputFactoryRegistry
,
Extensions
as
EditorExtensions
,
IFileInputFactory
,
EditorInput
,
SideBySideEditorInput
,
IEditorInputWithOptions
,
isEditorInputWithOptions
,
EditorOptions
,
TextEditorOptions
,
IEditorIdentifier
,
IEditorCloseEvent
,
ITextEditor
,
ITextDiffEditor
,
ITextSideBySideEditor
,
toResource
,
SideBySideEditor
,
IRevertOptions
,
SaveReason
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorInput
,
IEditor
,
GroupIdentifier
,
IFileEditorInput
,
IUntitledTextResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditorInputFactoryRegistry
,
Extensions
as
EditorExtensions
,
IFileInputFactory
,
EditorInput
,
SideBySideEditorInput
,
IEditorInputWithOptions
,
isEditorInputWithOptions
,
EditorOptions
,
TextEditorOptions
,
IEditorIdentifier
,
IEditorCloseEvent
,
ITextEditor
,
ITextDiffEditor
,
ITextSideBySideEditor
,
toResource
,
SideBySideEditor
,
IRevertOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
ResourceEditorInput
}
from
'
vs/workbench/common/editor/resourceEditorInput
'
;
import
{
DataUriEditorInput
}
from
'
vs/workbench/common/editor/dataUriEditorInput
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
...
...
@@ -28,8 +28,6 @@ import { IEditorGroupView, IEditorOpeningEvent, EditorServiceImpl } from 'vs/wor
import
{
ILabelService
}
from
'
vs/platform/label/common/label
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
withNullAsUndefined
}
from
'
vs/base/common/types
'
;
import
{
IFilesConfigurationService
,
AutoSaveMode
}
from
'
vs/workbench/services/filesConfiguration/common/filesConfigurationService
'
;
import
{
IHostService
}
from
'
vs/workbench/services/host/browser/host
'
;
type
CachedEditorInput
=
ResourceEditorInput
|
IFileEditorInput
|
DataUriEditorInput
;
type
OpenInEditorGroup
=
IEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
;
...
...
@@ -61,7 +59,6 @@ export class EditorService extends Disposable implements EditorServiceImpl {
private
lastActiveEditor
:
IEditorInput
|
null
=
null
;
private
lastActiveGroupId
:
GroupIdentifier
|
null
=
null
;
private
lastActiveEditorControlDisposable
=
this
.
_register
(
new
DisposableStore
());
constructor
(
@
IEditorGroupsService
private
readonly
editorGroupService
:
IEditorGroupsService
,
...
...
@@ -69,9 +66,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
@
IInstantiationService
private
readonly
instantiationService
:
IInstantiationService
,
@
ILabelService
private
readonly
labelService
:
ILabelService
,
@
IFileService
private
readonly
fileService
:
IFileService
,
@
IConfigurationService
private
readonly
configurationService
:
IConfigurationService
,
@
IFilesConfigurationService
private
readonly
filesConfigurationService
:
IFilesConfigurationService
,
@
IHostService
private
readonly
hostService
:
IHostService
@
IConfigurationService
private
readonly
configurationService
:
IConfigurationService
)
{
super
();
...
...
@@ -86,33 +81,6 @@ export class EditorService extends Disposable implements EditorServiceImpl {
this
.
editorGroupService
.
whenRestored
.
then
(()
=>
this
.
onEditorsRestored
());
this
.
editorGroupService
.
onDidActiveGroupChange
(
group
=>
this
.
handleActiveEditorChange
(
group
));
this
.
editorGroupService
.
onDidAddGroup
(
group
=>
this
.
registerGroupListeners
(
group
as
IEditorGroupView
));
// Auto save support
this
.
_register
(
this
.
onDidActiveEditorChange
(()
=>
this
.
onEditorFocusLost
()));
this
.
_register
(
this
.
hostService
.
onDidChangeFocus
(
focused
=>
this
.
onWindowFocusChange
(
focused
)));
}
private
onEditorFocusLost
():
void
{
this
.
maybeTriggerSaveAll
(
SaveReason
.
FOCUS_CHANGE
);
}
private
onWindowFocusChange
(
focused
:
boolean
):
void
{
if
(
!
focused
)
{
this
.
maybeTriggerSaveAll
(
SaveReason
.
WINDOW_CHANGE
);
}
}
private
maybeTriggerSaveAll
(
reason
:
SaveReason
):
void
{
const
mode
=
this
.
filesConfigurationService
.
getAutoSaveMode
();
// Determine if we need to save all. In case of a window focus change we also save if auto save mode
// is configured to be ON_FOCUS_CHANGE (editor focus change)
if
(
(
reason
===
SaveReason
.
WINDOW_CHANGE
&&
(
mode
===
AutoSaveMode
.
ON_FOCUS_CHANGE
||
mode
===
AutoSaveMode
.
ON_WINDOW_CHANGE
))
||
(
reason
===
SaveReason
.
FOCUS_CHANGE
&&
mode
===
AutoSaveMode
.
ON_FOCUS_CHANGE
)
)
{
this
.
saveAll
({
reason
});
}
}
private
onEditorsRestored
():
void
{
...
...
@@ -150,18 +118,6 @@ export class EditorService extends Disposable implements EditorServiceImpl {
this
.
lastActiveGroupId
=
activeGroup
.
id
;
this
.
lastActiveEditor
=
activeGroup
.
activeEditor
;
// Dispose previous active control listeners
this
.
lastActiveEditorControlDisposable
.
clear
();
// Listen to focus changes on control for auto save
const
controlsToObserve
:
ICodeEditor
[]
=
[];
if
(
isCodeEditor
(
this
.
activeTextEditorWidget
))
{
controlsToObserve
.
push
(
this
.
activeTextEditorWidget
);
}
else
if
(
isDiffEditor
(
this
.
activeTextEditorWidget
))
{
controlsToObserve
.
push
(
this
.
activeTextEditorWidget
.
getOriginalEditor
(),
this
.
activeTextEditorWidget
.
getModifiedEditor
());
}
controlsToObserve
.
forEach
(
control
=>
this
.
lastActiveEditorControlDisposable
.
add
(
control
.
onDidBlurEditorWidget
(()
=>
this
.
onEditorFocusLost
())));
// Fire event to outside parties
this
.
_onDidActiveEditorChange
.
fire
();
}
...
...
@@ -824,9 +780,7 @@ export class DelegatingEditorService extends EditorService {
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
ILabelService
labelService
:
ILabelService
,
@
IFileService
fileService
:
IFileService
,
@
IConfigurationService
configurationService
:
IConfigurationService
,
@
IFilesConfigurationService
filesConfigurationService
:
IFilesConfigurationService
,
@
IHostService
hostService
:
IHostService
@
IConfigurationService
configurationService
:
IConfigurationService
)
{
super
(
editorGroupService
,
...
...
@@ -834,9 +788,7 @@ export class DelegatingEditorService extends EditorService {
instantiationService
,
labelService
,
fileService
,
configurationService
,
filesConfigurationService
,
hostService
configurationService
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录