Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
8c684d1b
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
8c684d1b
编写于
7月 07, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement #8278
上级
db21b743
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
58 deletion
+66
-58
src/vs/workbench/parts/search/browser/searchResultsView.ts
src/vs/workbench/parts/search/browser/searchResultsView.ts
+4
-14
src/vs/workbench/parts/search/browser/searchViewlet.ts
src/vs/workbench/parts/search/browser/searchViewlet.ts
+1
-5
src/vs/workbench/parts/search/common/searchModel.ts
src/vs/workbench/parts/search/common/searchModel.ts
+57
-34
src/vs/workbench/parts/search/test/browser/searchViewlet.test.ts
...workbench/parts/search/test/browser/searchViewlet.test.ts
+1
-1
src/vs/workbench/parts/search/test/common/searchModel.test.ts
...vs/workbench/parts/search/test/common/searchModel.test.ts
+3
-4
未找到文件。
src/vs/workbench/parts/search/browser/searchResultsView.ts
浏览文件 @
8c684d1b
...
...
@@ -19,7 +19,7 @@ import { LeftRightWidget, IRenderer } from 'vs/base/browser/ui/leftRightWidget/l
import
{
ITree
,
IElementCallback
,
IDataSource
,
ISorter
,
IAccessibilityProvider
,
IFilter
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
{
ClickBehavior
,
DefaultController
}
from
'
vs/base/parts/tree/browser/treeDefaults
'
;
import
{
ContributableActionProvider
}
from
'
vs/workbench/browser/actionBarRegistry
'
;
import
{
Match
,
EmptyMatch
,
SearchResult
,
FileMatch
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
Match
,
SearchResult
,
FileMatch
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
...
...
@@ -104,7 +104,7 @@ class SearchActionProvider extends ContributableActionProvider {
actions
.
unshift
(
this
.
instantiationService
.
createInstance
(
ReplaceAllAction
,
tree
,
element
,
this
.
viewlet
));
}
}
if
(
element
instanceof
Match
&&
!
(
element
instanceof
EmptyMatch
)
)
{
if
(
element
instanceof
Match
)
{
if
(
input
.
searchModel
.
isReplaceActive
())
{
actions
.
unshift
(
this
.
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
element
,
this
.
viewlet
),
new
RemoveAction
(
tree
,
element
));
}
...
...
@@ -158,12 +158,6 @@ export class SearchRenderer extends ActionsRenderer {
return
widget
.
dispose
.
bind
(
widget
);
}
// Empty
else
if
(
element
instanceof
EmptyMatch
)
{
dom
.
addClass
(
domElement
,
'
linematch
'
);
$
(
'
a.plain.label
'
).
innerHtml
(
nls
.
localize
(
'
noMatches
'
,
"
no matches
"
)).
appendTo
(
domElement
);
}
// Match
else
if
(
element
instanceof
Match
)
{
dom
.
addClass
(
domElement
,
'
linematch
'
);
...
...
@@ -208,10 +202,6 @@ export class SearchAccessibilityProvider implements IAccessibilityProvider {
return
nls
.
localize
(
'
fileMatchAriaLabel
'
,
"
{0} matches in file {1} of folder {2}, Search result
"
,
element
.
count
(),
element
.
name
(),
paths
.
dirname
(
path
));
}
if
(
element
instanceof
EmptyMatch
)
{
return
nls
.
localize
(
'
emptyMatchAriaLabel
'
,
"
No matches
"
);
}
if
(
element
instanceof
Match
)
{
let
input
=
<
SearchResult
>
tree
.
getInput
();
if
(
input
.
searchModel
.
isReplaceActive
())
{
...
...
@@ -254,7 +244,7 @@ export class SearchController extends DefaultController {
let
result
=
false
;
let
element
=
tree
.
getFocus
();
if
(
element
instanceof
FileMatch
||
(
element
instanceof
Match
&&
input
.
searchModel
.
isReplaceActive
()
&&
!
(
element
instanceof
EmptyMatch
)
))
{
(
element
instanceof
Match
&&
input
.
searchModel
.
isReplaceActive
()))
{
new
RemoveAction
(
tree
,
element
).
run
().
done
(
null
,
errors
.
onUnexpectedError
);
result
=
true
;
}
...
...
@@ -266,7 +256,7 @@ export class SearchController extends DefaultController {
let
input
=
<
SearchResult
>
tree
.
getInput
();
let
result
=
false
;
let
element
=
tree
.
getFocus
();
if
(
element
instanceof
Match
&&
input
.
searchModel
.
isReplaceActive
()
&&
!
(
element
instanceof
EmptyMatch
)
)
{
if
(
element
instanceof
Match
&&
input
.
searchModel
.
isReplaceActive
())
{
this
.
instantiationService
.
createInstance
(
ReplaceAction
,
tree
,
element
,
this
.
viewlet
).
run
().
done
(
null
,
errors
.
onUnexpectedError
);
result
=
true
;
}
...
...
src/vs/workbench/parts/search/browser/searchViewlet.ts
浏览文件 @
8c684d1b
...
...
@@ -31,7 +31,7 @@ import {IEditorGroupService} from 'vs/workbench/services/group/common/groupServi
import
{
getOutOfWorkspaceEditorResources
}
from
'
vs/workbench/common/editor
'
;
import
{
FileChangeType
,
FileChangesEvent
,
EventType
as
FileEventType
}
from
'
vs/platform/files/common/files
'
;
import
{
Viewlet
}
from
'
vs/workbench/browser/viewlet
'
;
import
{
Match
,
EmptyMatch
,
FileMatch
,
SearchModel
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
Match
,
FileMatch
,
SearchModel
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
getExcludes
,
QueryBuilder
}
from
'
vs/workbench/parts/search/common/searchQuery
'
;
import
{
VIEWLET_ID
}
from
'
vs/workbench/parts/search/common/constants
'
;
import
{
MessageType
,
InputBox
}
from
'
vs/base/browser/ui/inputbox/inputBox
'
;
...
...
@@ -915,10 +915,6 @@ export class SearchViewlet extends Viewlet {
}
private
getSelectionFrom
(
element
:
FileMatchOrMatch
):
any
{
if
(
element
instanceof
EmptyMatch
)
{
return
void
0
;
}
let
match
:
Match
=
null
;
if
(
element
instanceof
Match
)
{
match
=
element
;
...
...
src/vs/workbench/parts/search/common/searchModel.ts
浏览文件 @
8c684d1b
...
...
@@ -68,13 +68,6 @@ export class Match {
}
}
export
class
EmptyMatch
extends
Match
{
constructor
(
parent
:
FileMatch
)
{
super
(
parent
,
null
,
Date
.
now
(),
Date
.
now
(),
Date
.
now
());
}
}
export
class
FileMatch
extends
Disposable
{
private
static
DecorationOption
:
IModelDecorationOptions
=
{
...
...
@@ -137,13 +130,6 @@ export class FileMatch extends Disposable {
}
}));
}
this
.
_register
(
this
.
onChange
(()
=>
{
if
(
this
.
count
()
===
0
)
{
let
emptyMatch
=
new
EmptyMatch
(
this
);
this
.
_matches
.
set
(
emptyMatch
.
id
(),
emptyMatch
);
}
}));
}
private
bindModel
(
model
:
IModel
):
void
{
...
...
@@ -197,7 +183,7 @@ export class FileMatch extends Disposable {
}
if
(
this
.
parent
().
showHighlights
)
{
this
.
_modelDecorations
=
this
.
_model
.
deltaDecorations
(
this
.
_modelDecorations
,
this
.
matches
().
filter
(
match
=>
!
(
match
instanceof
EmptyMatch
)).
map
(
match
=>
<
IModelDeltaDecoration
>
{
this
.
_modelDecorations
=
this
.
_model
.
deltaDecorations
(
this
.
_modelDecorations
,
this
.
matches
().
map
(
match
=>
<
IModelDeltaDecoration
>
{
range
:
match
.
range
(),
options
:
FileMatch
.
DecorationOption
}));
...
...
@@ -232,13 +218,7 @@ export class FileMatch extends Disposable {
}
public
count
():
number
{
let
result
=
0
;
this
.
matches
().
forEach
(
element
=>
{
if
(
!
(
element
instanceof
EmptyMatch
))
{
result
+=
1
;
}
});
return
result
;
return
this
.
matches
().
length
;
}
public
resource
():
URI
{
...
...
@@ -262,6 +242,8 @@ export class SearchResult extends Disposable {
public
onChange
:
Event
<
any
>
=
this
.
_onChange
.
event
;
private
_fileMatches
:
SimpleMap
<
URI
,
FileMatch
>
;
private
_unDisposedFileMatches
:
SimpleMap
<
URI
,
FileMatch
>
;
private
_query
:
Search
.
IPatternInfo
=
null
;
private
_showHighlights
:
boolean
;
private
_replacingAll
:
boolean
=
false
;
...
...
@@ -269,17 +251,22 @@ export class SearchResult extends Disposable {
@
IInstantiationService
private
instantiationService
:
IInstantiationService
)
{
super
();
this
.
_fileMatches
=
new
SimpleMap
<
URI
,
FileMatch
>
();
this
.
_unDisposedFileMatches
=
new
SimpleMap
<
URI
,
FileMatch
>
();
}
public
set
query
(
query
:
Search
.
IPatternInfo
)
{
this
.
_query
=
query
;
}
public
get
searchModel
():
SearchModel
{
return
this
.
_searchModel
;
}
public
add
(
query
:
Search
.
IPatternInfo
,
raw
:
Search
.
IFileMatch
[],
silent
:
boolean
=
false
):
void
{
public
add
(
raw
:
Search
.
IFileMatch
[],
silent
:
boolean
=
false
):
void
{
raw
.
forEach
((
rawFileMatch
)
=>
{
if
(
!
this
.
_fileMatches
.
has
(
rawFileMatch
.
resource
)){
let
fileMatch
=
this
.
instantiationService
.
createInstance
(
FileMatch
,
query
,
this
,
rawFileMatch
);
this
.
_fileMatches
.
set
(
rawFileMatch
.
resource
,
fileMatch
);
let
fileMatch
=
this
.
instantiationService
.
createInstance
(
FileMatch
,
this
.
_
query
,
this
,
rawFileMatch
);
this
.
doAdd
(
fileMatch
);
let
disposable
=
fileMatch
.
onChange
(()
=>
this
.
onFileChange
(
fileMatch
));
fileMatch
.
onDispose
(()
=>
disposable
.
dispose
());
}
...
...
@@ -290,20 +277,18 @@ export class SearchResult extends Disposable {
}
public
clear
():
void
{
this
.
matches
().
forEach
((
fileMatch
:
FileMatch
)
=>
fileMatch
.
dispose
());
this
.
_fileMatches
.
clear
();
this
.
disposeMatches
();
this
.
_onChange
.
fire
(
this
);
}
public
remove
(
match
:
FileMatch
):
void
{
this
.
_fileMatches
.
delete
(
match
.
resource
());
match
.
dispose
();
this
.
doRemove
(
match
);
this
.
_onChange
.
fire
(
this
);
}
public
replace
(
match
:
FileMatch
,
replaceText
:
string
):
TPromise
<
any
>
{
return
this
.
replaceService
.
replace
([
match
],
replaceText
).
then
(()
=>
{
this
.
remove
(
match
);
this
.
doRemove
(
match
,
false
);
});
}
...
...
@@ -350,11 +335,48 @@ export class SearchResult extends Disposable {
});
}
private
onFileChange
(
file
:
FileMatch
):
void
{
private
onFileChange
(
fileMatch
:
FileMatch
):
void
{
let
refreshFile
:
boolean
=
true
;
if
(
!
this
.
_fileMatches
.
has
(
fileMatch
.
resource
()))
{
this
.
doAdd
(
fileMatch
);
refreshFile
=
false
;
}
if
(
fileMatch
.
count
()
===
0
)
{
this
.
doRemove
(
fileMatch
,
false
);
refreshFile
=
false
;
}
if
(
!
this
.
_replacingAll
)
{
this
.
_onChange
.
fire
(
file
);
this
.
_onChange
.
fire
(
refreshFile
?
fileMatch
:
this
);
}
}
private
doAdd
(
fileMatch
:
FileMatch
):
void
{
this
.
_fileMatches
.
set
(
fileMatch
.
resource
(),
fileMatch
);
if
(
this
.
_unDisposedFileMatches
.
has
(
fileMatch
.
resource
()))
{
this
.
_unDisposedFileMatches
.
delete
(
fileMatch
.
resource
());
}
}
private
doRemove
(
fileMatch
:
FileMatch
,
dispose
:
boolean
=
true
):
void
{
this
.
_fileMatches
.
delete
(
fileMatch
.
resource
());
if
(
dispose
)
{
fileMatch
.
dispose
();
}
else
{
this
.
_unDisposedFileMatches
.
set
(
fileMatch
.
resource
(),
fileMatch
);
}
}
private
disposeMatches
():
void
{
this
.
_fileMatches
.
values
().
forEach
((
fileMatch
:
FileMatch
)
=>
fileMatch
.
dispose
());
this
.
_unDisposedFileMatches
.
values
().
forEach
((
fileMatch
:
FileMatch
)
=>
fileMatch
.
dispose
());
this
.
_fileMatches
.
clear
();
this
.
_unDisposedFileMatches
.
clear
();
}
public
dispose
():
void
{
this
.
disposeMatches
();
super
.
dispose
();
}
}
export
class
SearchModel
extends
Disposable
{
...
...
@@ -410,6 +432,7 @@ export class SearchModel extends Disposable {
this
.
searchResult
.
clear
();
this
.
_searchQuery
=
query
;
this
.
_searchResult
.
query
=
this
.
_searchQuery
.
contentPattern
;
this
.
progressTimer
=
this
.
telemetryService
.
timedPublicLog
(
'
searchResultsFirstRender
'
);
this
.
doneTimer
=
this
.
telemetryService
.
timedPublicLog
(
'
searchResultsFinished
'
);
this
.
timerEvent
=
timer
.
start
(
timer
.
Topic
.
WORKBENCH
,
'
Search
'
);
...
...
@@ -424,7 +447,7 @@ export class SearchModel extends Disposable {
private
onSearchCompleted
(
completed
:
ISearchComplete
):
ISearchComplete
{
this
.
timerEvent
.
stop
();
this
.
_searchResult
.
add
(
this
.
_searchQuery
.
contentPattern
,
completed
.
results
);
this
.
_searchResult
.
add
(
completed
.
results
);
this
.
telemetryService
.
publicLog
(
'
searchResultsShown
'
,
{
count
:
this
.
_searchResult
.
count
(),
fileCount
:
this
.
_searchResult
.
fileCount
()
});
this
.
doneTimer
.
stop
();
return
completed
;
...
...
@@ -441,7 +464,7 @@ export class SearchModel extends Disposable {
private
onSearchProgress
(
p
:
ISearchProgressItem
,
silent
:
boolean
):
void
{
if
(
p
.
resource
)
{
this
.
_searchResult
.
add
(
this
.
_searchQuery
.
contentPattern
,
[
p
],
silent
);
this
.
_searchResult
.
add
([
p
],
silent
);
this
.
progressTimer
.
stop
();
}
}
...
...
src/vs/workbench/parts/search/test/browser/searchViewlet.test.ts
浏览文件 @
8c684d1b
...
...
@@ -31,7 +31,7 @@ suite('Search - Viewlet', () => {
test
(
'
Data Source
'
,
function
()
{
let
ds
=
new
SearchDataSource
();
let
result
=
instantiation
.
createInstance
(
SearchResult
,
null
);
result
.
add
(
null
,
[{
result
.
add
([{
resource
:
uri
.
parse
(
'
file:///c:/foo
'
),
lineMatches
:
[{
lineNumber
:
1
,
preview
:
'
bar
'
,
offsetAndLengths
:
[[
0
,
1
]]
}]
}]);
...
...
src/vs/workbench/parts/search/test/common/searchModel.test.ts
浏览文件 @
8c684d1b
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Match
,
FileMatch
,
SearchResult
,
EmptyMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
Match
,
FileMatch
,
SearchResult
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
...
...
@@ -45,8 +45,7 @@ suite('Search - Model', () => {
}]);
let
lineMatch
=
fileMatch
.
matches
()[
0
];
fileMatch
.
remove
(
lineMatch
);
assert
.
equal
(
fileMatch
.
matches
().
length
,
1
);
assert
.
ok
(
fileMatch
.
matches
()[
0
]
instanceof
EmptyMatch
);
assert
.
equal
(
fileMatch
.
matches
().
length
,
0
);
});
test
(
'
File Match
'
,
function
()
{
...
...
@@ -77,7 +76,7 @@ suite('Search - Model', () => {
}]
});
}
searchResult
.
add
(
null
,
raw
);
searchResult
.
add
(
raw
);
assert
.
equal
(
searchResult
.
isEmpty
(),
false
);
assert
.
equal
(
searchResult
.
matches
().
length
,
10
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录