Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ee9f1e7e
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(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ee9f1e7e
编写于
2月 07, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Quickpick items search reveals octicons used in the items (fixes #21243)
上级
a475e27b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
158 addition
and
6 deletion
+158
-6
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+103
-0
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+50
-1
src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
.../workbench/browser/parts/quickopen/quickOpenController.ts
+5
-5
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
ee9f1e7e
...
...
@@ -7,6 +7,7 @@
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
{
LRUCache
}
from
'
vs/base/common/map
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
ltrim
}
from
'
vs/base/common/strings
'
;
export
interface
IFilter
{
// Returns null if word doesn't match.
...
...
@@ -341,6 +342,108 @@ export function matchesFuzzy(word: string, wordToMatchAgainst: string, enableSep
return
enableSeparateSubstringMatching
?
fuzzySeparateFilter
(
word
,
wordToMatchAgainst
)
:
fuzzyContiguousFilter
(
word
,
wordToMatchAgainst
);
}
const
octiconStartMarker
=
'
$(
'
;
export
function
matchesFuzzyOcticonAware
(
word
:
string
,
wordToMatchAgainst
:
string
,
enableSeparateSubstringMatching
=
false
):
IMatch
[]
{
// Return early if there are no octicon markers in the word to match against
const
firstOcticonIndex
=
wordToMatchAgainst
.
indexOf
(
octiconStartMarker
);
if
(
firstOcticonIndex
===
-
1
)
{
return
matchesFuzzy
(
word
,
wordToMatchAgainst
,
enableSeparateSubstringMatching
);
}
const
octiconOffsets
:
number
[]
=
[];
let
wordToMatchAgainstWithoutOcticons
:
string
=
''
;
function
appendChars
(
chars
:
string
)
{
if
(
chars
)
{
wordToMatchAgainstWithoutOcticons
+=
chars
;
for
(
let
i
=
0
;
i
<
chars
.
length
;
i
++
)
{
octiconOffsets
.
push
(
octiconsOffset
);
// make sure to fill in octicon offsets
}
}
}
let
currentOcticonStart
=
-
1
;
let
currentOcticonValue
:
string
=
''
;
let
octiconsOffset
=
0
;
let
char
:
string
;
let
nextChar
:
string
;
let
offset
=
firstOcticonIndex
;
const
length
=
wordToMatchAgainst
.
length
;
// Append all characters until the first octicon
appendChars
(
wordToMatchAgainst
.
substr
(
0
,
firstOcticonIndex
));
// example: $(file-symlink-file) my cool $(other-octicon) entry
while
(
offset
<
length
)
{
char
=
wordToMatchAgainst
[
offset
];
nextChar
=
wordToMatchAgainst
[
offset
+
1
];
// beginning of octicon: some value $( <--
if
(
char
===
octiconStartMarker
[
0
]
&&
nextChar
===
octiconStartMarker
[
1
])
{
currentOcticonStart
=
offset
;
// if we had a previous potential octicon value without
// the closing ')', it was actually not an octicon and
// so we have to add it to the actual value
appendChars
(
currentOcticonValue
);
currentOcticonValue
=
octiconStartMarker
;
offset
++
;
// jump over '('
}
// end of octicon: some value $(some-octicon) <--
else
if
(
char
===
'
)
'
&&
currentOcticonStart
!==
-
1
)
{
const
currentOcticonLength
=
offset
-
currentOcticonStart
+
1
;
// +1 to include the closing ')'
octiconsOffset
+=
currentOcticonLength
;
currentOcticonStart
=
-
1
;
currentOcticonValue
=
''
;
}
// within octicon
else
if
(
currentOcticonStart
!==
-
1
)
{
currentOcticonValue
+=
char
;
}
// any value outside of octicons
else
{
appendChars
(
char
);
}
offset
++
;
}
// if we had a previous potential octicon value without
// the closing ')', it was actually not an octicon and
// so we have to add it to the actual value
appendChars
(
currentOcticonValue
);
// Trim the word to match against because it could have leading
// whitespace now if the word started with an octicon
const
wordToMatchAgainstWithoutOcticonsTrimmed
=
ltrim
(
wordToMatchAgainstWithoutOcticons
,
'
'
);
const
leadingWhitespaceOffset
=
wordToMatchAgainstWithoutOcticons
.
length
-
wordToMatchAgainstWithoutOcticonsTrimmed
.
length
;
// match on value without octicons
const
matches
=
matchesFuzzy
(
word
,
wordToMatchAgainstWithoutOcticonsTrimmed
,
enableSeparateSubstringMatching
);
// Map matches back to offsets with octicons and trimming
if
(
matches
)
{
for
(
let
i
=
0
;
i
<
matches
.
length
;
i
++
)
{
const
octiconOffset
=
octiconOffsets
[
matches
[
i
].
start
]
/* octicon offsets at index */
+
leadingWhitespaceOffset
/* overall leading whitespace offset */
;
matches
[
i
].
start
+=
octiconOffset
;
matches
[
i
].
end
+=
octiconOffset
;
}
}
return
matches
;
}
export
function
skipScore
(
pattern
:
string
,
word
:
string
,
patternMaxWhitespaceIgnore
?:
number
):
[
number
,
number
[]]
{
pattern
=
pattern
.
toLowerCase
();
word
=
word
.
toLowerCase
();
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
ee9f1e7e
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
,
fuzzyScore
,
IMatch
,
fuzzyScoreGraceful
,
fuzzyScoreGracefulAggressive
}
from
'
vs/base/common/filters
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
,
fuzzyScore
,
IMatch
,
fuzzyScoreGraceful
,
fuzzyScoreGracefulAggressive
,
matchesFuzzy
,
matchesFuzzyOcticonAware
}
from
'
vs/base/common/filters
'
;
function
filterOk
(
filter
:
IFilter
,
word
:
string
,
wordToMatchAgainst
:
string
,
highlights
?:
{
start
:
number
;
end
:
number
;
}[])
{
let
r
=
filter
(
word
,
wordToMatchAgainst
);
...
...
@@ -442,4 +442,53 @@ suite('Filters', () => {
assertMatches
(
'
cno
'
,
'
co_new
'
,
'
^c^o_^new
'
,
fuzzyScoreGraceful
);
assertMatches
(
'
cno
'
,
'
co_new
'
,
'
^c^o_^new
'
,
fuzzyScoreGracefulAggressive
);
});
test
(
'
matchesFuzzzyOcticonAware
'
,
function
()
{
// Camel Case
filterOk
(
matchesFuzzy
,
'
ccr
'
,
'
CamelCaseRocks
'
,
[
{
start
:
0
,
end
:
1
},
{
start
:
5
,
end
:
6
},
{
start
:
9
,
end
:
10
}
]);
filterOk
(
matchesFuzzyOcticonAware
,
'
ccr
'
,
'
$(octicon)CamelCaseRocks$(octicon)
'
,
[
{
start
:
10
,
end
:
11
},
{
start
:
15
,
end
:
16
},
{
start
:
19
,
end
:
20
}
]);
filterOk
(
matchesFuzzyOcticonAware
,
'
ccr
'
,
'
$(octicon) CamelCaseRocks $(octicon)
'
,
[
{
start
:
11
,
end
:
12
},
{
start
:
16
,
end
:
17
},
{
start
:
20
,
end
:
21
}
]);
filterOk
(
matchesFuzzyOcticonAware
,
'
iut
'
,
'
$(octicon) Indent $(octico) Using $(octic) Tpaces
'
,
[
{
start
:
11
,
end
:
12
},
{
start
:
28
,
end
:
29
},
{
start
:
43
,
end
:
44
},
]);
// Prefix
filterOk
(
matchesFuzzy
,
'
using
'
,
'
Indent Using Spaces
'
,
[
{
start
:
7
,
end
:
12
}
]);
filterOk
(
matchesFuzzyOcticonAware
,
'
using
'
,
'
$(octicon) Indent Using Spaces
'
,
[
{
start
:
18
,
end
:
23
},
]);
// Broken Octicon
filterOk
(
matchesFuzzyOcticonAware
,
'
octicon
'
,
'
This $(octicon Indent Using Spaces
'
,
[
{
start
:
7
,
end
:
14
},
]);
filterOk
(
matchesFuzzyOcticonAware
,
'
indent
'
,
'
This $octicon Indent Using Spaces
'
,
[
{
start
:
14
,
end
:
20
},
]);
});
});
src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
浏览文件 @
ee9f1e7e
...
...
@@ -11,7 +11,6 @@ import nls = require('vs/nls');
import
*
as
browser
from
'
vs/base/browser/browser
'
;
import
{
Dimension
,
withElementById
}
from
'
vs/base/browser/builder
'
;
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
filters
=
require
(
'
vs/base/common/filters
'
);
import
DOM
=
require
(
'
vs/base/browser/dom
'
);
import
URI
from
'
vs/base/common/uri
'
;
import
*
as
resources
from
'
vs/base/common/resources
'
;
...
...
@@ -55,6 +54,7 @@ import { FileKind, IFileService } from 'vs/platform/files/common/files';
import
{
scoreItem
,
ScorerCache
,
compareItemsByScore
,
prepareQuery
}
from
'
vs/base/parts/quickopen/common/quickOpenScorer
'
;
import
{
getBaseLabel
}
from
'
vs/base/common/labels
'
;
import
{
WorkbenchTree
}
from
'
vs/platform/list/browser/listService
'
;
import
{
matchesFuzzyOcticonAware
}
from
'
vs/base/common/filters
'
;
const
HELP_PREFIX
=
'
?
'
;
...
...
@@ -431,12 +431,12 @@ export class QuickOpenController extends Component implements IQuickOpenService
});
}
// Filter by value
// Filter by value
(since we support octicons, use octicon aware fuzzy matching)
else
{
entries
.
forEach
(
entry
=>
{
const
labelHighlights
=
filters
.
matchesFuzzy
(
value
,
entry
.
getLabel
());
const
descriptionHighlights
=
options
.
matchOnDescription
&&
filters
.
matchesFuzzy
(
value
,
entry
.
getDescription
());
const
detailHighlights
=
options
.
matchOnDetail
&&
entry
.
getDetail
()
&&
filters
.
matchesFuzzy
(
value
,
entry
.
getDetail
());
const
labelHighlights
=
matchesFuzzyOcticonAware
(
value
,
entry
.
getLabel
());
const
descriptionHighlights
=
options
.
matchOnDescription
&&
matchesFuzzyOcticonAware
(
value
,
entry
.
getDescription
());
const
detailHighlights
=
options
.
matchOnDetail
&&
entry
.
getDetail
()
&&
matchesFuzzyOcticonAware
(
value
,
entry
.
getDetail
());
if
(
entry
.
shouldAlwaysShow
()
||
labelHighlights
||
descriptionHighlights
||
detailHighlights
)
{
entry
.
setHighlights
(
labelHighlights
,
descriptionHighlights
,
detailHighlights
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录