Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b98b4d67
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,发现更多精彩内容 >>
提交
b98b4d67
编写于
12月 08, 2015
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fuzzy flag to comparer and matcher in quick open model
上级
f9c0e7b7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
15 deletion
+35
-15
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+1
-6
src/vs/base/parts/quickopen/browser/quickOpenModel.ts
src/vs/base/parts/quickopen/browser/quickOpenModel.ts
+34
-9
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
b98b4d67
...
...
@@ -251,12 +251,7 @@ const fuzzyContiguousFilter = or(matchesPrefix, matchesCamelCase, matchesContigu
const
fuzzySeparateFilter
=
or
(
matchesPrefix
,
matchesCamelCase
,
matchesSubString
);
const
fuzzyRegExpCache
:
{
[
key
:
string
]:
RegExp
;
}
=
{};
let
defaultFuzzyMatching
=
SubstringMatching
.
Contiguous
;
export
function
setDefaultFuzzyMatching
(
matcher
:
SubstringMatching
):
void
{
defaultFuzzyMatching
=
matcher
;
}
export
function
matchesFuzzy
(
word
:
string
,
wordToMatchAgainst
:
string
,
matcher
=
defaultFuzzyMatching
):
IMatch
[]
{
export
function
matchesFuzzy
(
word
:
string
,
wordToMatchAgainst
:
string
,
matcher
=
SubstringMatching
.
Contiguous
):
IMatch
[]
{
// Form RegExp for wildcard matches
let
regexp
=
fuzzyRegExpCache
[
word
];
...
...
src/vs/base/parts/quickopen/browser/quickOpenModel.ts
浏览文件 @
b98b4d67
...
...
@@ -136,12 +136,31 @@ export class QuickOpenEntry {
/**
* A good default sort implementation for quick open entries respecting highlight information
* as well as associated resources.
*
* Supports fuzzy scoring when the option is enabled.
*/
public
static
compare
(
elementA
:
QuickOpenEntry
,
elementB
:
QuickOpenEntry
,
lookFor
:
string
):
number
{
public
static
compare
(
elementA
:
QuickOpenEntry
,
elementB
:
QuickOpenEntry
,
lookFor
:
string
,
enableFuzzyScoring
=
false
):
number
{
// Normalize
if
(
lookFor
)
{
lookFor
=
Strings
.
stripWildcards
(
lookFor
).
toLowerCase
();
lookFor
=
Strings
.
stripWildcards
(
lookFor
);
}
// Fuzzy scoring is special
if
(
enableFuzzyScoring
)
{
const
labelAScore
=
Strings
.
score
(
elementA
.
getLabel
(),
lookFor
);
const
labelBScore
=
Strings
.
score
(
elementB
.
getLabel
(),
lookFor
);
if
(
labelAScore
!==
labelBScore
)
{
return
labelAScore
>
labelBScore
?
-
1
:
1
;
}
const
descriptionAScore
=
Strings
.
score
(
elementA
.
getDescription
(),
lookFor
);
const
descriptionBScore
=
Strings
.
score
(
elementB
.
getDescription
(),
lookFor
);
if
(
descriptionAScore
!==
descriptionBScore
)
{
return
descriptionAScore
>
descriptionBScore
?
-
1
:
1
;
}
}
// Give matches with label highlights higher priority over
...
...
@@ -167,36 +186,42 @@ export class QuickOpenEntry {
}
}
return
compareAnything
(
nameA
,
nameB
,
lookFor
);
return
compareAnything
(
nameA
,
nameB
,
lookFor
.
toLowerCase
()
);
}
public
static
highlight
(
entry
:
QuickOpenEntry
,
lookFor
:
string
):
{
labelHighlights
:
IHighlight
[],
descriptionHighlights
:
IHighlight
[]
}
{
/**
* A good default highlight implementation for an entry with label and description.
*
* Supports fuzzy matching when the option is enabled.
*/
public
static
highlight
(
entry
:
QuickOpenEntry
,
lookFor
:
string
,
enableFuzzyMatching
=
false
):
{
labelHighlights
:
IHighlight
[],
descriptionHighlights
:
IHighlight
[]
}
{
let
labelHighlights
:
IHighlight
[]
=
[];
let
descriptionHighlights
:
IHighlight
[]
=
[];
let
matcher
=
enableFuzzyMatching
?
Filters
.
SubstringMatching
.
Separate
:
Filters
.
SubstringMatching
.
Contiguous
;
// Highlight file aware
if
(
entry
.
getResource
())
{
// Highlight only inside label
if
(
lookFor
.
indexOf
(
Paths
.
nativeSep
)
<
0
)
{
labelHighlights
=
Filters
.
matchesFuzzy
(
lookFor
,
entry
.
getLabel
());
labelHighlights
=
Filters
.
matchesFuzzy
(
lookFor
,
entry
.
getLabel
()
,
matcher
);
}
// Highlight in label and description
else
{
descriptionHighlights
=
Filters
.
matchesFuzzy
(
Strings
.
trim
(
lookFor
,
Paths
.
nativeSep
),
entry
.
getDescription
());
descriptionHighlights
=
Filters
.
matchesFuzzy
(
Strings
.
trim
(
lookFor
,
Paths
.
nativeSep
),
entry
.
getDescription
()
,
matcher
);
// If we have no highlights, assume that the match is split among name and parent folder
if
(
!
descriptionHighlights
||
!
descriptionHighlights
.
length
)
{
labelHighlights
=
Filters
.
matchesFuzzy
(
Paths
.
basename
(
lookFor
),
entry
.
getLabel
());
descriptionHighlights
=
Filters
.
matchesFuzzy
(
Strings
.
trim
(
Paths
.
dirname
(
lookFor
),
Paths
.
nativeSep
),
entry
.
getDescription
());
labelHighlights
=
Filters
.
matchesFuzzy
(
Paths
.
basename
(
lookFor
),
entry
.
getLabel
()
,
matcher
);
descriptionHighlights
=
Filters
.
matchesFuzzy
(
Strings
.
trim
(
Paths
.
dirname
(
lookFor
),
Paths
.
nativeSep
),
entry
.
getDescription
()
,
matcher
);
}
}
}
// Highlight by label otherwise
else
{
labelHighlights
=
Filters
.
matchesFuzzy
(
lookFor
,
entry
.
getLabel
());
labelHighlights
=
Filters
.
matchesFuzzy
(
lookFor
,
entry
.
getLabel
()
,
matcher
);
}
return
{
labelHighlights
,
descriptionHighlights
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录