Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
26f73817
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
26f73817
编写于
10月 06, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
history: avoid typed input for editor navigation (for #13283)
上级
4f9fe722
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
40 deletion
+47
-40
src/vs/workbench/services/history/browser/history.ts
src/vs/workbench/services/history/browser/history.ts
+47
-40
未找到文件。
src/vs/workbench/services/history/browser/history.ts
浏览文件 @
26f73817
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
errors
=
require
(
'
vs/base/common/errors
'
);
import
platform
=
require
(
'
vs/base/common/platform
'
);
import
nls
=
require
(
'
vs/nls
'
);
...
...
@@ -16,7 +17,7 @@ import {BaseTextEditor} from 'vs/workbench/browser/parts/editor/textEditor';
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IHistoryService
}
from
'
vs/workbench/services/history/common/history
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
IEditorInput
,
ITextEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorInput
,
ITextEditorOptions
,
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
...
...
@@ -222,7 +223,7 @@ export abstract class BaseHistoryService {
}
interface
IStackEntry
{
input
:
IEditorInput
;
input
:
IEditorInput
|
IResourceInput
;
options
?:
ITextEditorOptions
;
}
...
...
@@ -335,9 +336,9 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private
navigate
():
void
{
const
state
=
this
.
stack
[
this
.
index
];
const
entry
=
this
.
stack
[
this
.
index
];
let
options
=
state
.
options
;
let
options
=
entry
.
options
;
if
(
options
)
{
options
.
revealIfVisible
=
true
;
}
else
{
...
...
@@ -345,7 +346,16 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
this
.
blockStackChanges
=
true
;
this
.
editorService
.
openEditor
(
state
.
input
,
options
).
done
(()
=>
{
let
openEditorPromise
:
TPromise
<
IBaseEditor
>
;
if
(
entry
.
input
instanceof
EditorInput
)
{
openEditorPromise
=
this
.
editorService
.
openEditor
(
entry
.
input
,
options
);
}
else
{
const
resourceInput
=
entry
.
input
as
IResourceInput
;
openEditorPromise
=
this
.
editorService
.
openEditor
({
resource
:
resourceInput
.
resource
,
options
});
}
openEditorPromise
.
done
(()
=>
{
this
.
blockStackChanges
=
false
;
},
(
error
)
=>
{
this
.
blockStackChanges
=
false
;
...
...
@@ -472,7 +482,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private
handleNonTextEditorEvent
(
editor
:
IBaseEditor
):
void
{
const
currentStack
=
this
.
stack
[
this
.
index
];
if
(
currentStack
&&
currentStack
.
input
.
matches
(
editor
.
input
))
{
if
(
currentStack
&&
this
.
matches
(
editor
.
input
,
currentStack
.
input
))
{
return
;
// do not push same editor input again
}
...
...
@@ -493,15 +503,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
let
replace
=
false
;
if
(
this
.
stack
[
this
.
index
])
{
const
currentEntry
=
this
.
stack
[
this
.
index
];
if
(
currentEntry
.
input
.
matches
(
input
)
&&
this
.
sameOptions
(
currentEntry
.
options
,
options
))
{
if
(
this
.
matches
(
input
,
currentEntry
.
input
)
&&
this
.
sameOptions
(
currentEntry
.
options
,
options
))
{
replace
=
true
;
}
}
const
entry
=
{
input
,
options
};
const
stackInput
=
this
.
preferResourceInput
(
input
);
const
entry
=
{
input
:
stackInput
,
options
};
// If we are not at the end of history, we remove anything after
if
(
this
.
stack
.
length
>
this
.
index
+
1
)
{
...
...
@@ -527,11 +535,23 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
}
// Restore on dispose
const
onceDispose
=
once
(
input
.
onDispose
);
onceDispose
(()
=>
{
this
.
restoreInStack
(
input
);
});
// Remove this from the stack unless the stack input is a resource
// that can easily be restored even when the input gets disposed
if
(
stackInput
instanceof
EditorInput
)
{
const
onceDispose
=
once
(
stackInput
.
onDispose
);
onceDispose
(()
=>
{
this
.
removeFromStack
(
input
);
});
}
}
private
preferResourceInput
(
input
:
IEditorInput
):
IEditorInput
|
IResourceInput
{
const
fileInput
=
asFileEditorInput
(
input
);
if
(
fileInput
)
{
return
{
resource
:
fileInput
.
getResource
()
};
}
return
input
;
}
private
sameOptions
(
optionsA
?:
ITextEditorOptions
,
optionsB
?:
ITextEditorOptions
):
boolean
{
...
...
@@ -557,29 +577,6 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return
s1
.
startLineNumber
===
s2
.
startLineNumber
;
// we consider the history entry same if we are on the same line
}
private
restoreInStack
(
input
:
IEditorInput
):
void
{
let
restoredInput
:
EditorInput
;
let
restored
=
false
;
this
.
stack
.
forEach
((
e
,
i
)
=>
{
if
(
e
.
input
.
matches
(
input
))
{
if
(
!
restored
)
{
restoredInput
=
this
.
restoreInput
(
input
);
restored
=
true
;
}
if
(
restoredInput
)
{
this
.
stack
[
i
].
input
=
restoredInput
;
}
else
{
this
.
stack
.
splice
(
i
,
1
);
if
(
this
.
index
>=
i
)
{
this
.
index
--
;
// reduce index if the element is before index
}
}
}
});
}
private
restoreInput
(
input
:
IEditorInput
):
EditorInput
{
if
(
input
instanceof
EditorInput
)
{
const
factory
=
this
.
registry
.
getEditorInputFactory
(
input
.
getTypeId
());
...
...
@@ -596,7 +593,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private
removeFromStack
(
input
:
IEditorInput
):
void
{
this
.
stack
.
forEach
((
e
,
i
)
=>
{
if
(
e
.
input
.
matches
(
input
))
{
if
(
this
.
matches
(
input
,
e
.
input
))
{
this
.
stack
.
splice
(
i
,
1
);
if
(
this
.
index
>=
i
)
{
this
.
index
--
;
// reduce index if the element is before index
...
...
@@ -625,6 +622,16 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return
group
.
getEditors
().
some
(
e
=>
this
.
matchesFile
(
resource
,
e
));
}
private
matches
(
typedInput
:
IEditorInput
,
input
:
IEditorInput
|
IResourceInput
):
boolean
{
if
(
input
instanceof
EditorInput
)
{
return
input
.
matches
(
typedInput
);
}
const
resourceInput
=
input
as
IResourceInput
;
return
this
.
matchesFile
(
resourceInput
.
resource
,
typedInput
);
}
private
matchesFile
(
resource
:
URI
,
input
:
IEditorInput
):
boolean
{
const
fileInput
=
asFileEditorInput
(
input
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录