Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
690a65cd
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,发现更多精彩内容 >>
提交
690a65cd
编写于
12月 12, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #16554
上级
ac052e01
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
42 deletion
+62
-42
src/vs/workbench/parts/search/browser/replaceContributions.ts
...vs/workbench/parts/search/browser/replaceContributions.ts
+4
-1
src/vs/workbench/parts/search/browser/replaceService.ts
src/vs/workbench/parts/search/browser/replaceService.ts
+58
-41
未找到文件。
src/vs/workbench/parts/search/browser/replaceContributions.ts
浏览文件 @
690a65cd
...
...
@@ -4,8 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
IReplaceService
}
from
'
vs/workbench/parts/search/common/replace
'
;
import
{
ReplaceService
}
from
'
vs/workbench/parts/search/browser/replaceService
'
;
import
{
ReplaceService
,
ReplacePreviewContentProvider
}
from
'
vs/workbench/parts/search/browser/replaceService
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
IWorkbenchContributionsRegistry
,
Extensions
as
WorkbenchExtensions
}
from
'
vs/workbench/common/contributions
'
;
export
function
registerContributions
():
void
{
registerSingleton
(
IReplaceService
,
ReplaceService
);
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
).
registerWorkbenchContribution
(
ReplacePreviewContentProvider
);
}
src/vs/workbench/parts/search/browser/replaceService.ts
浏览文件 @
690a65cd
...
...
@@ -21,7 +21,37 @@ import { IProgressRunner } from 'vs/platform/progress/common/progress';
import
{
IDiffEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
DiffEditorInput
}
from
'
vs/workbench/common/editor/diffEditorInput
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
ITextModelResolverService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
ITextModelResolverService
,
ITextModelContentProvider
,
ITextEditorModel
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
IWorkbenchContribution
}
from
'
vs/workbench/common/contributions
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
export
class
ReplacePreviewContentProvider
implements
ITextModelContentProvider
,
IWorkbenchContribution
{
constructor
(
@
IModelService
private
modelService
:
IModelService
,
@
ITextModelResolverService
private
textModelResolverService
:
ITextModelResolverService
)
{
this
.
textModelResolverService
.
registerTextModelContentProvider
(
network
.
Schemas
.
internal
,
this
);
}
public
getId
():
string
{
return
'
replace.preview.contentprovider
'
;
}
public
provideTextContent
(
uri
:
URI
):
TPromise
<
IModel
>
{
if
(
uri
.
fragment
===
'
preview
'
)
{
const
fileResource
=
uri
.
with
({
scheme
:
network
.
Schemas
.
file
,
fragment
:
''
});
return
this
.
textModelResolverService
.
createModelReference
(
fileResource
).
then
(
ref
=>
{
const
textEditorModel
=
ref
.
object
.
textEditorModel
;
const
model
=
this
.
modelService
.
createModel
(
textEditorModel
.
getValue
(),
textEditorModel
.
getMode
(),
uri
);
ref
.
dispose
();
return
model
;
});
}
return
null
;
}
}
class
EditorInputCache
{
...
...
@@ -30,7 +60,6 @@ class EditorInputCache {
constructor
(
private
replaceService
:
ReplaceService
,
private
editorService
:
IWorkbenchEditorService
,
private
modelService
:
IModelService
,
private
textModelResolverService
:
ITextModelResolverService
)
{
this
.
cache
=
new
Map
.
LinkedMap
<
URI
,
TPromise
<
DiffEditorInput
>>
();
...
...
@@ -55,22 +84,24 @@ class EditorInputCache {
public
refreshInput
(
fileMatch
:
FileMatch
,
reloadFromSource
:
boolean
=
false
):
void
{
let
editorInputPromise
=
this
.
cache
.
get
(
fileMatch
.
resource
());
if
(
editorInputPromise
)
{
editorInputPromise
.
done
(()
=>
{
if
(
reloadFromSource
)
{
this
.
textModelResolverService
.
createModelReference
(
fileMatch
.
resource
()).
done
(
ref
=>
{
const
model
=
ref
.
object
;
if
(
model
.
textEditorModel
)
{
let
replaceResource
=
this
.
getReplaceResource
(
fileMatch
.
resource
());
this
.
modelService
.
getModel
(
replaceResource
).
setValue
(
model
.
textEditorModel
.
getValue
());
this
.
replaceService
.
replace
(
fileMatch
,
null
,
replaceResource
);
ref
.
dispose
();
editorInputPromise
.
then
(
replacePreviewInput
=>
{
replacePreviewInput
.
modifiedInput
.
resolve
()
.
then
(
editorModel
=>
{
const
replaceResourceModel
=
(
<
ITextEditorModel
>
editorModel
).
textEditorModel
;
if
(
reloadFromSource
)
{
this
.
textModelResolverService
.
createModelReference
(
fileMatch
.
resource
()).
done
(
ref
=>
{
const
model
=
ref
.
object
;
if
(
model
.
textEditorModel
)
{
replaceResourceModel
.
setValue
(
model
.
textEditorModel
.
getValue
());
this
.
replaceService
.
replace
(
fileMatch
,
null
,
replaceResourceModel
.
uri
);
}
ref
.
dispose
();
});
}
else
{
replaceResourceModel
.
undo
();
this
.
replaceService
.
replace
(
fileMatch
,
null
,
replaceResourceModel
.
uri
);
}
});
}
else
{
let
replaceResource
=
this
.
getReplaceResource
(
fileMatch
.
resource
());
this
.
modelService
.
getModel
(
replaceResource
).
undo
();
this
.
replaceService
.
replace
(
fileMatch
,
null
,
replaceResource
);
}
});
}
}
...
...
@@ -95,39 +126,25 @@ class EditorInputCache {
}
private
createInput
(
fileMatch
:
FileMatch
):
TPromise
<
DiffEditorInput
>
{
return
TPromise
.
join
([
this
.
createLeftInput
(
fileMatch
),
this
.
createRightInput
(
fileMatch
)]).
then
(
inputs
=>
{
const
[
left
,
right
]
=
inputs
;
let
editorInput
=
new
DiffEditorInput
(
nls
.
localize
(
'
fileReplaceChanges
'
,
"
{0} ↔ {1} (Replace Preview)
"
,
fileMatch
.
name
(),
fileMatch
.
name
()),
undefined
,
<
EditorInput
>
left
,
<
EditorInput
>
right
);
editorInput
.
onDispose
(()
=>
this
.
cleanInput
(
fileMatch
.
resource
()));
return
editorInput
;
});
return
TPromise
.
join
([
this
.
createLeftInput
(
fileMatch
),
this
.
createRightInput
(
fileMatch
)])
.
then
(([
left
,
right
])
=>
{
let
editorInput
=
new
DiffEditorInput
(
nls
.
localize
(
'
fileReplaceChanges
'
,
"
{0} ↔ {1} (Replace Preview)
"
,
fileMatch
.
name
(),
fileMatch
.
name
()),
undefined
,
<
EditorInput
>
left
,
<
EditorInput
>
right
);
editorInput
.
onDispose
(()
=>
this
.
cleanInput
(
fileMatch
.
resource
()));
return
editorInput
;
});
}
private
createLeftInput
(
element
:
FileMatch
):
TPromise
<
IEditorInput
>
{
return
this
.
editorService
.
createInput
({
resource
:
element
.
resource
()
});
private
createLeftInput
(
fileMatch
:
FileMatch
):
TPromise
<
IEditorInput
>
{
return
this
.
editorService
.
createInput
({
resource
:
fileMatch
.
resource
()
});
}
private
createRightInput
(
element
:
FileMatch
):
TPromise
<
IEditorInput
>
{
return
this
.
textModelResolverService
.
createModelReference
(
element
.
resource
()).
then
(
ref
=>
{
const
model
=
ref
.
object
;
let
textEditorModel
=
model
.
textEditorModel
;
let
replaceResource
=
this
.
getReplaceResource
(
element
.
resource
());
this
.
modelService
.
createModel
(
textEditorModel
.
getValue
(),
textEditorModel
.
getMode
(),
replaceResource
);
ref
.
dispose
();
return
this
.
editorService
.
createInput
({
resource
:
replaceResource
});
});
private
createRightInput
(
fileMatch
:
FileMatch
):
TPromise
<
IEditorInput
>
{
return
this
.
editorService
.
createInput
({
resource
:
fileMatch
.
resource
().
with
({
scheme
:
network
.
Schemas
.
internal
,
fragment
:
'
preview
'
})
});
}
private
cleanInput
(
resourceUri
:
URI
):
void
{
this
.
modelService
.
destroyModel
(
this
.
getReplaceResource
(
resourceUri
));
this
.
cache
.
delete
(
resourceUri
);
}
private
getReplaceResource
(
resource
:
URI
):
URI
{
return
resource
.
with
({
scheme
:
network
.
Schemas
.
internal
,
fragment
:
'
preview
'
});
}
}
export
class
ReplaceService
implements
IReplaceService
{
...
...
@@ -143,7 +160,7 @@ export class ReplaceService implements IReplaceService {
@
IModelService
private
modelService
:
IModelService
,
@
ITextModelResolverService
private
textModelResolverService
:
ITextModelResolverService
)
{
this
.
cache
=
new
EditorInputCache
(
this
,
editorService
,
modelService
,
textModelResolverService
);
this
.
cache
=
new
EditorInputCache
(
this
,
editorService
,
textModelResolverService
);
}
public
replace
(
match
:
Match
):
TPromise
<
any
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录