Skip to content

Commit

Permalink
Merge 53fd29c into 4bcf727
Browse files Browse the repository at this point in the history
  • Loading branch information
deerawan committed Jul 26, 2019
2 parents 4bcf727 + 53fd29c commit 1a37c3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
26 changes: 15 additions & 11 deletions src/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export class Dash {

constructor(OS: string, option: DashOption) {
this.OS = OS;

this.URIHandler = {
darwin: 'open -g',
linux: 'zeal',
// Same technique as Silverlake Software's "Search Docsets" extension,
// which is written by Velocity's developer and is tested to work with current Velocity on W10.
win32: 'cmd.exe /c start "" ',
}[this.OS] || 'zeal';

this.URIHandler =
{
darwin: 'open -g',
linux: 'zeal',
// Same technique as Silverlake Software's "Search Docsets" extension,
// which is written by Velocity's developer and is tested to work with current Velocity on W10.
win32: 'cmd.exe /c start "" ', // TODO: do we need extra space?
}[this.OS] || 'zeal';

this.option = option;
}
Expand All @@ -25,11 +26,14 @@ export class Dash {
* @return {string} dash handler and uri
*/
getCommand(query: string, docsets: string[] = []): string {
const keys = (docsets || []).map(docset => `${this.option.exactDocset ? "exact:" : ""}${docset}`).join(",");
const keys = (docsets || [])
.map(docset => `${this.option.exactDocset ? 'exact:' : ''}${docset}`)
.join(',');
const encodedQuery = encodeURIComponent(query);
return `${this.URIHandler} "dash-plugin://query=${encodedQuery}${keys?`&keys=${keys}`:``}"`;
return `${this.URIHandler} "dash-plugin://query=${encodedQuery}${keys
? `&keys=${keys}`
: ``}"`;
}

}

export interface DashOption {
Expand Down
28 changes: 10 additions & 18 deletions test/dash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ suite('Dash Tests', () => {
const dash = new Dash('darwin', dashOptionExactDocsetEnabled);
const uri = dash.getCommand('size', ['css', 'less']);

assert.equal(uri, 'open -g "dash-plugin://query=size&keys=exact:css,exact:less"');
assert.equal(
uri,
'open -g "dash-plugin://query=size&keys=exact:css,exact:less"'
);
});

test('Get command with no keys for macOS', () => {
Expand All @@ -24,22 +27,25 @@ suite('Dash Tests', () => {

assert.equal(
uri,
'start dash-plugin:// && start dash-plugin://query=size^&keys=exact:css,exact:less'
'cmd.exe /c start "" "dash-plugin://query=size&keys=exact:css,exact:less"'
);
});

test('Get command with no keys for Windows', () => {
const dash = new Dash('win32', dashOptionExactDocsetEnabled);
const uri = dash.getCommand('size');

assert.equal(uri, 'start dash-plugin:// && start dash-plugin://query=size');
assert.equal(uri, 'cmd.exe /c start "" "dash-plugin://query=size"');
});

test('Get command with keys for Linux', () => {
const dash = new Dash('linux', dashOptionExactDocsetEnabled);
const uri = dash.getCommand('size', ['css', 'less']);

assert.equal(uri, 'zeal "dash-plugin://query=size&keys=exact:css,exact:less"');
assert.equal(
uri,
'zeal "dash-plugin://query=size&keys=exact:css,exact:less"'
);
});

test('Get command with no keys for Linux', () => {
Expand All @@ -49,20 +55,6 @@ suite('Dash Tests', () => {
assert.equal(uri, 'zeal "dash-plugin://query=size"');
});

test('Get keys with exist docset', () => {
const dash = new Dash('darwin', dashOptionExactDocsetEnabled);
const keys = dash.getKeys(['css', 'less']);

assert.equal(keys, 'exact:css,exact:less');
});

test('Get keys with empty docset', () => {
const dash = new Dash('darwin', dashOptionExactDocsetEnabled);
const keys = dash.getKeys([]);

assert.equal(keys, '');
});

test('Exact docset disabled', () => {
const dashOptionExactDocsetDisabled: DashOption = { exactDocset: false };

Expand Down

0 comments on commit 1a37c3f

Please sign in to comment.