Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fzf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
fzf
Commits
5624a892
Unverified
Commit
5624a892
authored
6 years ago
by
Junegunn Choi
Browse files
Options
Downloads
Patches
Plain Diff
Inverse-only matches should not reorder the remaining results
Fix #1458
parent
63c42b14
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/core.go
+1
-0
1 addition, 0 deletions
src/core.go
src/matcher.go
+1
-1
1 addition, 1 deletion
src/matcher.go
src/pattern.go
+12
-1
12 additions, 1 deletion
src/pattern.go
test/test_go.rb
+13
-0
13 additions, 0 deletions
test/test_go.rb
with
27 additions
and
2 deletions
src/core.go
+
1
−
0
View file @
5624a892
...
...
@@ -149,6 +149,7 @@ func Run(opts *Options, revision string) {
}
pattern
:=
patternBuilder
([]
rune
(
*
opts
.
Filter
))
matcher
.
sort
=
pattern
.
sortable
found
:=
false
if
streamingFilter
{
...
...
This diff is collapsed.
Click to expand it.
src/matcher.go
+
1
−
1
View file @
5624a892
...
...
@@ -230,5 +230,5 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final
}
else
{
event
=
reqRetry
}
m
.
reqBox
.
Set
(
event
,
MatchRequest
{
chunks
,
pattern
,
final
,
sort
})
m
.
reqBox
.
Set
(
event
,
MatchRequest
{
chunks
,
pattern
,
final
,
sort
&&
pattern
.
sortable
})
}
This diff is collapsed.
Click to expand it.
src/pattern.go
+
12
−
1
View file @
5624a892
...
...
@@ -52,6 +52,7 @@ type Pattern struct {
forward
bool
text
[]
rune
termSets
[]
termSet
sortable
bool
cacheable
bool
cacheKey
string
delimiter
Delimiter
...
...
@@ -101,18 +102,27 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
}
caseSensitive
:=
true
sortable
:=
true
termSets
:=
[]
termSet
{}
if
extended
{
termSets
=
parseTerms
(
fuzzy
,
caseMode
,
normalize
,
asString
)
// We should not sort the result if there are only inverse search terms
sortable
=
false
Loop
:
for
_
,
termSet
:=
range
termSets
{
for
idx
,
term
:=
range
termSet
{
if
!
term
.
inv
{
sortable
=
true
}
// If the query contains inverse search terms or OR operators,
// we cannot cache the search scope
if
!
cacheable
||
idx
>
0
||
term
.
inv
||
fuzzy
&&
term
.
typ
!=
termFuzzy
||
!
fuzzy
&&
term
.
typ
!=
termExact
{
cacheable
=
false
break
Loop
if
sortable
{
// Can't break until we see at least one non-inverse term
break
Loop
}
}
}
}
...
...
@@ -134,6 +144,7 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
forward
:
forward
,
text
:
[]
rune
(
asString
),
termSets
:
termSets
,
sortable
:
sortable
,
cacheable
:
cacheable
,
nth
:
nth
,
delimiter
:
delimiter
,
...
...
This diff is collapsed.
Click to expand it.
test/test_go.rb
+
13
−
0
View file @
5624a892
...
...
@@ -1519,6 +1519,19 @@ class TestGoFZF < TestBase
assert_equal
[
'foo bar'
],
`
#{
FZF
}
-f'^foo
\\
bar$' <
#{
tempname
}
`
.
lines
.
map
(
&
:chomp
)
assert_equal
input
.
lines
.
count
-
1
,
`
#{
FZF
}
-f'!^foo
\\
bar$' <
#{
tempname
}
`
.
lines
.
count
end
def
test_inverse_only_search_should_not_sort_the_result
# Filter
assert_equal
(
%w[aaaaa b ccc]
,
`printf '%s
\n
' aaaaa b ccc BAD |
#{
FZF
}
-f '!bad'`
.
lines
.
map
(
&
:chomp
))
# Interactive
tmux
.
send_keys
(
%[printf '%s
\n
' aaaaa b ccc BAD |
#{
FZF
}
-q '!bad']
,
:Enter
)
tmux
.
until
{
|
lines
|
lines
.
item_count
==
4
&&
lines
.
match_count
==
3
}
tmux
.
until
{
|
lines
|
lines
[
-
3
]
==
'> aaaaa'
}
tmux
.
until
{
|
lines
|
lines
[
-
4
]
==
' b'
}
tmux
.
until
{
|
lines
|
lines
[
-
5
]
==
' ccc'
}
end
end
module
TestShell
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment