diff options
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/actions/find.js | 6 | ||||
-rw-r--r-- | src/content/actions/operation.js | 9 | ||||
-rw-r--r-- | src/content/components/top-content/find.js | 23 | ||||
-rw-r--r-- | src/content/components/top-content/index.js | 4 |
4 files changed, 38 insertions, 4 deletions
diff --git a/src/content/actions/find.js b/src/content/actions/find.js index 90c9de9..2d301fb 100644 --- a/src/content/actions/find.js +++ b/src/content/actions/find.js @@ -1,6 +1,6 @@ // // window.find(aString, aCaseSensitive, aBackwards, aWrapAround, -// aWholeWord, aSearchInFrames, aShowDialog); +// aWholeWord, aSearchInFrames); // // NOTE: window.find is not standard API // https://developer.mozilla.org/en-US/docs/Web/API/Window/find @@ -17,7 +17,7 @@ const hide = () => { const next = (keyword) => { // TODO Error on no matched - window.find(keyword, false, false, true, false, true, false); + window.find(keyword, false, false, true, false, true); return { type: actions.FIND_SET_KEYWORD, keyword, @@ -26,7 +26,7 @@ const next = (keyword) => { const prev = (keyword) => { // TODO Error on no matched - window.find(keyword, false, true, true, false, true, false); + window.find(keyword, false, true, true, false, true); return { type: actions.FIND_SET_KEYWORD, keyword, diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 897f361..767f14b 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -6,6 +6,7 @@ import * as urls from 'content/urls'; import * as consoleFrames from 'content/console-frames'; import * as addonActions from './addon'; +// eslint-disable-next-line complexity const exec = (operation) => { switch (operation.type) { case operations.ADDON_ENABLE: @@ -14,6 +15,14 @@ const exec = (operation) => { return addonActions.disable(); case operations.ADDON_TOGGLE_ENABLED: return addonActions.toggleEnabled(); + case operations.FIND_NEXT: + return window.top.postMessage(JSON.stringify({ + type: messages.FIND_NEXT, + }), '*'); + case operations.FIND_PREV: + return window.top.postMessage(JSON.stringify({ + type: messages.FIND_PREV, + }), '*'); case operations.SCROLL_VERTICALLY: return scrolls.scrollVertically(window, operation.count); case operations.SCROLL_HORIZONALLY: diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js new file mode 100644 index 0000000..6696f00 --- /dev/null +++ b/src/content/components/top-content/find.js @@ -0,0 +1,23 @@ +import * as findActions from 'content/actions/find'; +import messages from 'shared/messages'; + +export default class FindComponent { + constructor(win, store) { + this.win = win; + this.store = store; + + messages.onMessage(this.onMessage.bind(this)); + } + + onMessage(message) { + let state = this.store.getState().find; + switch (message.type) { + case messages.CONSOLE_ENTER_FIND: + return this.store.dispatch(findActions.next(message.text)); + case messages.FIND_NEXT: + return this.store.dispatch(findActions.next(state.keyword)); + case messages.FIND_PREV: + return this.store.dispatch(findActions.prev(state.keyword)); + } + } +} diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index 5124f83..cf21ec4 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -1,5 +1,6 @@ import CommonComponent from '../common'; import FollowController from './follow-controller'; +import FindComponent from './find'; import * as consoleFrames from '../../console-frames'; import * as addonActions from '../../actions/addon'; import messages from 'shared/messages'; @@ -14,6 +15,7 @@ export default class TopContent { new CommonComponent(win, store); // eslint-disable-line no-new new FollowController(win, store); // eslint-disable-line no-new + new FindComponent(win, store); // eslint-disable-line no-new // TODO make component consoleFrames.initialize(this.win.document); @@ -47,7 +49,7 @@ export default class TopContent { onMessage(message) { switch (message.type) { - case messages.CONSOLE_HIDE_COMMAND: + case messages.CONSOLE_UNFOCUS: this.win.focus(); consoleFrames.blur(window.document); return Promise.resolve(); |