Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Handle entries with spaces #3

Merged
merged 3 commits into from
Feb 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/filter-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ describe "filtering", ->
it "does not throw an exception", ->
candidates = ['/']
expect(filter(candidates, 'bar', maxResults: 1)).toEqual []

describe "when the entries contains spaces", ->
it "treats spaces as slashes", ->
candidates = ['/bar/foo', '/foo/bar']
expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/bar/foo']

it "weighs basename matches higher", ->
candidates = ['/bar/foo', '/foo/bar foo']
expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/foo/bar foo']
candidates = ['/barfoo/foo', '/foo/barfoo']
expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/foo/barfoo']
1 change: 1 addition & 0 deletions src/filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ basenameScore = (string, query, score) ->
module.exports = (candidates, query, {key, maxResults}={}) ->
if query
queryHasNoSlashes = query.indexOf('/') is -1
query = query.replace(/\ /g, '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just trying to replace spaces right? I don't think you need to escape \ the space, am I missing something?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coffeeScript freaks out when you use an regex like / /. So I think /\ /g is the way to go.

scoredCandidates = []
for candidate in candidates
string = if key? then candidate[key] else candidate
Expand Down