Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ac3b2005
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,发现更多精彩内容 >>
提交
ac3b2005
编写于
9月 12, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement history helper and tests - #5508
上级
8e562d6d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
184 addition
and
0 deletion
+184
-0
src/vs/base/common/history.ts
src/vs/base/common/history.ts
+70
-0
src/vs/base/test/common/history.test.ts
src/vs/base/test/common/history.test.ts
+114
-0
未找到文件。
src/vs/base/common/history.ts
0 → 100644
浏览文件 @
ac3b2005
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
ArraySet
}
from
'
vs/base/common/set
'
;
import
{
INavigator
,
ArrayNavigator
}
from
'
vs/base/common/iterator
'
;
export
class
HistoryNavigator
<
T
>
implements
INavigator
<
T
>
{
private
_history
:
ArraySet
<
T
>
;
private
_limit
:
number
;
private
_navigator
:
ArrayNavigator
<
T
>
;
constructor
(
history
:
T
[]
=
[],
limit
:
number
=
10
)
{
this
.
_history
=
new
ArraySet
(
history
);
this
.
_limit
=
limit
;
this
.
_onChange
();
}
public
add
(
t
:
T
)
{
this
.
_history
.
set
(
t
);
this
.
_onChange
();
}
public
next
():
T
{
if
(
this
.
_navigator
.
next
())
{
return
this
.
_navigator
.
current
();
}
this
.
last
();
return
null
;
}
public
previous
():
T
{
if
(
this
.
_navigator
.
previous
())
{
return
this
.
_navigator
.
current
();
}
this
.
first
();
return
null
;
}
public
current
():
T
{
return
this
.
_navigator
.
current
();
}
public
parent
():
T
{
return
null
;
}
public
first
():
T
{
return
this
.
_navigator
.
first
();
}
public
last
():
T
{
return
this
.
_navigator
.
last
();
}
private
_onChange
()
{
this
.
_reduceToLimit
();
this
.
_navigator
=
new
ArrayNavigator
(
this
.
_history
.
elements
);
this
.
_navigator
.
last
();
}
private
_reduceToLimit
()
{
let
data
=
this
.
_history
.
elements
;
if
(
data
.
length
>
this
.
_limit
)
{
this
.
_history
=
new
ArraySet
<
T
>
(
data
.
slice
(
data
.
length
-
this
.
_limit
));
}
}
}
\ No newline at end of file
src/vs/base/test/common/history.test.ts
0 → 100644
浏览文件 @
ac3b2005
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
HistoryNavigator
}
from
'
vs/base/common/history
'
;
suite
(
'
History Navigator
'
,
()
=>
{
test
(
'
create reduces the input to limit
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
2
);
assert
.
deepEqual
([
'
3
'
,
'
4
'
],
toArray
(
testObject
));
});
test
(
'
create sets the position to last
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
assert
.
equal
(
'
4
'
,
testObject
.
current
());
assert
.
equal
(
null
,
testObject
.
next
());
assert
.
equal
(
'
3
'
,
testObject
.
previous
());
});
test
(
'
last returns last element
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
testObject
.
first
();
assert
.
equal
(
'
4
'
,
testObject
.
last
());
});
test
(
'
first returns first element
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
assert
.
equal
(
'
2
'
,
testObject
.
first
());
});
test
(
'
next returns next element
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
testObject
.
first
();
assert
.
equal
(
'
3
'
,
testObject
.
next
());
assert
.
equal
(
'
4
'
,
testObject
.
next
());
assert
.
equal
(
null
,
testObject
.
next
());
});
test
(
'
previous returns previous element
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
assert
.
equal
(
'
3
'
,
testObject
.
previous
());
assert
.
equal
(
'
2
'
,
testObject
.
previous
());
assert
.
equal
(
null
,
testObject
.
previous
());
});
test
(
'
next on last element returs null and remains on last
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
testObject
.
first
();
testObject
.
last
();
assert
.
equal
(
'
4
'
,
testObject
.
current
());
assert
.
equal
(
null
,
testObject
.
next
());
});
test
(
'
previous on first element returs null and remains on first
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
testObject
.
first
();
assert
.
equal
(
'
2
'
,
testObject
.
current
());
assert
.
equal
(
null
,
testObject
.
previous
());
});
test
(
'
add reduces the input to limit
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
2
);
testObject
.
add
(
'
5
'
);
assert
.
deepEqual
([
'
4
'
,
'
5
'
],
toArray
(
testObject
));
});
test
(
'
adding existing element changes the position
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
2
);
testObject
.
add
(
'
2
'
);
assert
.
deepEqual
([
'
4
'
,
'
2
'
],
toArray
(
testObject
));
});
test
(
'
add resets the navigator to last
'
,
function
()
{
let
testObject
=
new
HistoryNavigator
([
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
],
3
);
testObject
.
first
();
testObject
.
add
(
'
5
'
);
assert
.
equal
(
'
5
'
,
testObject
.
current
());
assert
.
equal
(
null
,
testObject
.
next
());
});
function
toArray
(
historyNavigator
:
HistoryNavigator
<
string
>
):
string
[]
{
let
result
=
[];
historyNavigator
.
first
();
if
(
historyNavigator
.
current
())
{
do
{
result
.
push
(
historyNavigator
.
current
());
}
while
(
historyNavigator
.
next
());
}
return
result
;
}
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录