parent
7e35d11f65
commit
3c67cc0a00
8 changed files with 75 additions and 47 deletions
@ -0,0 +1,11 @@ |
|||||||
|
import actions from '../actions'; |
||||||
|
|
||||||
|
export function requestCompletions(line) { |
||||||
|
let command = line.split(' ', 1)[0]; |
||||||
|
let keywords = line.replace(command + ' ', ''); |
||||||
|
return { |
||||||
|
type: actions.BACKGROUND_REQUEST_COMPLETIONS, |
||||||
|
command, |
||||||
|
keywords |
||||||
|
}; |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
import * as tabs from '../background/tabs'; |
||||||
|
import * as consoleActions from '../actions/console'; |
||||||
|
import actions from '../actions'; |
||||||
|
|
||||||
|
const doCompletion = (command, keywords, sendto) => { |
||||||
|
if (command === 'buffer') { |
||||||
|
return tabs.getCompletions(keywords).then((tabs) => { |
||||||
|
let items = tabs.map((tab) => { |
||||||
|
return { |
||||||
|
caption: tab.title, |
||||||
|
content: tab.title, |
||||||
|
url: tab.url, |
||||||
|
icon: tab.favIconUrl |
||||||
|
} |
||||||
|
}); |
||||||
|
let completions = { |
||||||
|
name: "Buffers", |
||||||
|
items: items |
||||||
|
}; |
||||||
|
return browser.tabs.sendMessage( |
||||||
|
sendto,
|
||||||
|
consoleActions.setCompletions([completions])); |
||||||
|
}); |
||||||
|
} |
||||||
|
return Promise.resolve(); |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default function reducer(state, action = {}, sendto) { |
||||||
|
// TODO hide sendto object
|
||||||
|
switch (action.type) { |
||||||
|
case actions.BACKGROUND_REQUEST_COMPLETIONS: |
||||||
|
return doCompletion(action.command, action.keywords, sendto); |
||||||
|
default: |
||||||
|
return Promise.resolve(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
import { expect } from "chai"; |
||||||
|
import actions from '../../src/actions'; |
||||||
|
import * as backgroundActions from '../../src/actions/background'; |
||||||
|
|
||||||
|
describe("background actions", () => { |
||||||
|
describe("requestCompletions", () => { |
||||||
|
it('create BACKGROUND_REQUEST_COMPLETIONS action', () => { |
||||||
|
let action = backgroundActions.requestCompletions('buffer hoge fuga'); |
||||||
|
expect(action.type).to.equal(actions.BACKGROUND_REQUEST_COMPLETIONS); |
||||||
|
expect(action.command).to.equal('buffer'); |
||||||
|
expect(action.keywords).to.equal('hoge fuga'); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
Reference in new issue