Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f0644a47
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,发现更多精彩内容 >>
提交
f0644a47
编写于
9月 10, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests for #11475
上级
cdeee0ab
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
195 addition
and
11 deletion
+195
-11
src/vs/base/common/iterator.ts
src/vs/base/common/iterator.ts
+38
-4
src/vs/test/utils/instantiationTestUtils.ts
src/vs/test/utils/instantiationTestUtils.ts
+11
-0
src/vs/workbench/parts/search/browser/searchActions.ts
src/vs/workbench/parts/search/browser/searchActions.ts
+7
-7
src/vs/workbench/parts/search/test/browser/searchActions.test.ts
...workbench/parts/search/test/browser/searchActions.test.ts
+139
-0
未找到文件。
src/vs/base/common/iterator.ts
浏览文件 @
f0644a47
...
...
@@ -12,9 +12,9 @@ export interface IIterator<T> {
export
class
ArrayIterator
<
T
>
implements
IIterator
<
T
>
{
private
items
:
T
[];
pr
ivate
start
:
number
;
pr
ivate
end
:
number
;
pr
ivate
index
:
number
;
pr
otected
start
:
number
;
pr
otected
end
:
number
;
pr
otected
index
:
number
;
constructor
(
items
:
T
[],
start
:
number
=
0
,
end
:
number
=
items
.
length
)
{
this
.
items
=
items
;
...
...
@@ -25,8 +25,11 @@ export class ArrayIterator<T> implements IIterator<T> {
public
next
():
T
{
this
.
index
=
Math
.
min
(
this
.
index
+
1
,
this
.
end
);
return
this
.
current
();
}
if
(
this
.
index
===
this
.
end
)
{
protected
current
():
T
{
if
(
this
.
index
===
this
.
start
-
1
||
this
.
index
===
this
.
end
)
{
return
null
;
}
...
...
@@ -34,6 +37,37 @@ export class ArrayIterator<T> implements IIterator<T> {
}
}
export
class
ArrayNavigator
<
T
>
extends
ArrayIterator
<
T
>
implements
INavigator
<
T
>
{
constructor
(
items
:
T
[],
start
:
number
=
0
,
end
:
number
=
items
.
length
)
{
super
(
items
,
start
,
end
);
}
public
current
():
T
{
return
super
.
current
();
}
public
previous
():
T
{
this
.
index
=
Math
.
max
(
this
.
index
-
1
,
this
.
start
-
1
);
return
this
.
current
();
}
public
first
():
T
{
this
.
index
=
this
.
start
;
return
this
.
current
();
}
public
last
():
T
{
this
.
index
=
this
.
end
-
1
;
return
this
.
current
();
}
public
parent
():
T
{
return
null
;
}
}
export
class
MappedIterator
<
T
,
R
>
implements
IIterator
<
R
>
{
constructor
(
protected
iterator
:
IIterator
<
T
>
,
protected
fn
:
(
item
:
T
)
=>
R
)
{
...
...
src/vs/test/utils/instantiationTestUtils.ts
浏览文件 @
f0644a47
...
...
@@ -5,6 +5,7 @@
import
*
as
sinon
from
'
sinon
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
{
LinkedMap
}
from
'
vs/base/common/map
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
...
...
@@ -26,6 +27,8 @@ import { MarkerService } from 'vs/platform/markers/common/markerService';
import
{
IMarkerService
}
from
'
vs/platform/markers/common/markers
'
;
import
{
IReplaceService
}
from
'
vs/workbench/parts/search/common/replace
'
;
import
{
ReplaceService
}
from
'
vs/workbench/parts/search/browser/replaceService
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
WorkbenchKeybindingService
}
from
'
vs/workbench/services/keybinding/electron-browser/keybindingService
'
;
interface
IServiceMock
<
T
>
{
id
:
ServiceIdentifier
<
T
>
;
...
...
@@ -48,6 +51,7 @@ export class TestInstantiationService extends InstantiationService {
this
.
_servciesMap
.
set
(
IExtensionService
,
SimpleExtensionService
);
this
.
_servciesMap
.
set
(
IMarkerService
,
MarkerService
);
this
.
_servciesMap
.
set
(
IReplaceService
,
ReplaceService
);
this
.
_servciesMap
.
set
(
IKeybindingService
,
WorkbenchKeybindingService
);
}
public
mock
<
T
>
(
service
:
ServiceIdentifier
<
T
>
):
T
|
sinon
.
SinonMock
{
...
...
@@ -136,6 +140,13 @@ export class TestInstantiationService extends InstantiationService {
}
}
export
function
stubFunction
<
T
>
(
ctor
:
any
,
fnProperty
:
string
,
value
:
any
):
T
|
sinon
.
SinonStub
{
let
stub
=
sinon
.
createStubInstance
(
ctor
);
stub
[
fnProperty
].
restore
();
sinon
.
stub
(
stub
,
fnProperty
,
types
.
isFunction
(
value
)
?
value
:
()
=>
{
return
value
;
});
return
stub
;
}
interface
SinonOptions
{
mock
?:
boolean
;
stub
?:
boolean
;
...
...
src/vs/workbench/parts/search/browser/searchActions.ts
浏览文件 @
f0644a47
...
...
@@ -24,7 +24,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
Keybinding
,
KeyCode
,
KeyMod
,
CommonKeybindings
}
from
'
vs/base/common/keyCodes
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
asFileEditorInput
}
from
'
vs/workbench/common/editor
'
;
export
function
isSearchViewletFocussed
(
viewletService
:
IViewletService
):
boolean
{
let
activeViewlet
=
viewletService
.
getActiveViewlet
();
...
...
@@ -132,7 +132,7 @@ export abstract class AbstractSearchAndReplaceAction extends Action {
/**
* Returns element to focus after removing the given element
*/
p
rotected
getElementToFocusAfterRemoved
(
viewer
:
ITree
,
elementToBeRemoved
:
FileMatchOrMatch
):
FileMatchOrMatch
{
p
ublic
getElementToFocusAfterRemoved
(
viewer
:
ITree
,
elementToBeRemoved
:
FileMatchOrMatch
):
FileMatchOrMatch
{
let
elementToFocus
=
this
.
getNextElementAfterRemoved
(
viewer
,
elementToBeRemoved
);
if
(
!
elementToFocus
)
{
elementToFocus
=
this
.
getPreviousElementAfterRemoved
(
viewer
,
elementToBeRemoved
);
...
...
@@ -140,7 +140,7 @@ export abstract class AbstractSearchAndReplaceAction extends Action {
return
elementToFocus
;
}
p
rotected
getNextElementAfterRemoved
(
viewer
:
ITree
,
element
:
FileMatchOrMatch
):
FileMatchOrMatch
{
p
ublic
getNextElementAfterRemoved
(
viewer
:
ITree
,
element
:
FileMatchOrMatch
):
FileMatchOrMatch
{
let
navigator
:
INavigator
<
any
>
=
this
.
getNavigatorAt
(
element
,
viewer
);
if
(
element
instanceof
FileMatch
)
{
// If file match is removed then next element is the next file match
...
...
@@ -151,7 +151,7 @@ export abstract class AbstractSearchAndReplaceAction extends Action {
return
navigator
.
current
();
}
p
rotected
getPreviousElementAfterRemoved
(
viewer
:
ITree
,
element
:
FileMatchOrMatch
):
FileMatchOrMatch
{
p
ublic
getPreviousElementAfterRemoved
(
viewer
:
ITree
,
element
:
FileMatchOrMatch
):
FileMatchOrMatch
{
let
navigator
:
INavigator
<
any
>
=
this
.
getNavigatorAt
(
element
,
viewer
);
let
previousElement
=
navigator
.
previous
();
if
(
element
instanceof
Match
&&
element
.
parent
().
matches
().
length
===
1
)
{
...
...
@@ -272,9 +272,9 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
}
private
hasToOpenFile
():
boolean
{
let
activeInput
=
this
.
editorService
.
getActiveEditorInput
(
);
if
(
activeInput
instanceof
FileE
ditorInput
)
{
return
active
Input
.
getResource
().
fsPath
===
this
.
element
.
parent
().
resource
().
fsPath
;
const
editorInput
=
asFileEditorInput
(
this
.
editorService
.
getActiveEditorInput
()
);
if
(
e
ditorInput
)
{
return
editor
Input
.
getResource
().
fsPath
===
this
.
element
.
parent
().
resource
().
fsPath
;
}
return
false
;
}
...
...
src/vs/workbench/parts/search/test/browser/searchActions.test.ts
0 → 100644
浏览文件 @
f0644a47
/*---------------------------------------------------------------------------------------------
* 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
URI
from
'
vs/base/common/uri
'
;
import
{
TestInstantiationService
,
stubFunction
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
{
Match
,
FileMatch
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
ReplaceAction
}
from
'
vs/workbench/parts/search/browser/searchActions
'
;
import
{
ArrayNavigator
}
from
'
vs/base/common/iterator
'
;
import
{
IFileMatch
}
from
'
vs/platform/search/common/search
'
;
import
{
createMockModelService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
Tree
}
from
'
vs/base/parts/tree/browser/treeImpl
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
suite
(
'
Search Actions
'
,
()
=>
{
let
instantiationService
:
TestInstantiationService
;
let
counter
:
number
;
setup
(()
=>
{
instantiationService
=
new
TestInstantiationService
();
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
instantiationService
.
stub
(
IKeybindingService
);
counter
=
0
;
});
test
(
'
get next element to focus after removing a match when it has next sibling match
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
fileMatch2
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
),
aMatch
(
fileMatch1
),
fileMatch2
,
aMatch
(
fileMatch2
),
aMatch
(
fileMatch2
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
2
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
data
[
3
],
actual
);
});
test
(
'
get next element to focus after removing a match when it does not have next sibling match
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
fileMatch2
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
),
aMatch
(
fileMatch1
),
fileMatch2
,
aMatch
(
fileMatch2
),
aMatch
(
fileMatch2
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
5
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
data
[
4
],
actual
);
});
test
(
'
get next element to focus after removing a match when it does not have next sibling match and previous match is file match
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
fileMatch2
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
),
aMatch
(
fileMatch1
),
fileMatch2
,
aMatch
(
fileMatch2
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
4
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
data
[
2
],
actual
);
});
test
(
'
get next element to focus after removing a match when it is the only match
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
1
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
void
0
,
actual
);
});
test
(
'
get next element to focus after removing a file match when it has next sibling
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
fileMatch2
=
aFileMatch
();
let
fileMatch3
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
),
fileMatch2
,
aMatch
(
fileMatch2
),
fileMatch3
,
aMatch
(
fileMatch3
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
2
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
data
[
4
],
actual
);
});
test
(
'
get next element to focus after removing a file match when it has no next sibling
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
fileMatch2
=
aFileMatch
();
let
fileMatch3
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
),
fileMatch2
,
aMatch
(
fileMatch2
),
fileMatch3
,
aMatch
(
fileMatch3
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
4
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
data
[
3
],
actual
);
});
test
(
'
get next element to focus after removing a file match when it is only match
'
,
function
()
{
let
fileMatch1
=
aFileMatch
();
let
data
=
[
fileMatch1
,
aMatch
(
fileMatch1
)];
let
tree
=
aTree
(
data
);
let
target
=
data
[
0
];
let
testObject
:
ReplaceAction
=
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
target
,
null
);
let
actual
=
testObject
.
getElementToFocusAfterRemoved
(
tree
,
target
);
assert
.
equal
(
void
0
,
actual
);
});
function
aFileMatch
():
FileMatch
{
let
rawMatch
:
IFileMatch
=
{
resource
:
URI
.
file
(
'
somepath
'
+
++
counter
),
lineMatches
:
[]
};
return
instantiationService
.
createInstance
(
FileMatch
,
null
,
null
,
rawMatch
);
}
function
aMatch
(
fileMatch
:
FileMatch
):
Match
{
let
match
=
new
Match
(
fileMatch
,
'
some match
'
,
++
counter
,
0
,
2
);
fileMatch
.
add
(
match
);
return
match
;
}
function
aTree
(
elements
:
FileMatchOrMatch
[]):
any
{
return
stubFunction
(
Tree
,
'
getNavigator
'
,
()
=>
{
return
new
ArrayNavigator
(
elements
);
});
}
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录