diff options
Diffstat (limited to 'src/content/actions')
-rw-r--r-- | src/content/actions/find.js | 59 | ||||
-rw-r--r-- | src/content/actions/follow-controller.js | 3 | ||||
-rw-r--r-- | src/content/actions/operation.js | 8 | ||||
-rw-r--r-- | src/content/actions/setting.js | 9 |
4 files changed, 55 insertions, 24 deletions
diff --git a/src/content/actions/find.js b/src/content/actions/find.js index 80d6210..c7345cc 100644 --- a/src/content/actions/find.js +++ b/src/content/actions/find.js @@ -5,6 +5,7 @@ // NOTE: window.find is not standard API // https://developer.mozilla.org/en-US/docs/Web/API/Window/find +import messages from 'shared/messages'; import actions from 'content/actions'; import * as consoleFrames from '../console-frames'; @@ -14,6 +15,13 @@ const postPatternNotFound = (pattern) => { 'Pattern not found: ' + pattern); }; +const postPatternFound = (pattern) => { + return consoleFrames.postInfo( + window.document, + 'Pattern found: ' + pattern, + ); +}; + const find = (string, backwards) => { let caseSensitive = false; let wrapScan = true; @@ -24,32 +32,49 @@ const find = (string, backwards) => { return window.find(string, caseSensitive, backwards, wrapScan); }; -const findNext = (keyword, reset, backwards) => { +const findNext = (currentKeyword, reset, backwards) => { if (reset) { window.getSelection().removeAllRanges(); } - let found = find(keyword, backwards); - if (!found) { - window.getSelection().removeAllRanges(); - found = find(keyword, backwards); + let promise = Promise.resolve(currentKeyword); + if (currentKeyword) { + browser.runtime.sendMessage({ + type: messages.FIND_SET_KEYWORD, + keyword: currentKeyword, + }); + } else { + promise = browser.runtime.sendMessage({ + type: messages.FIND_GET_KEYWORD, + }); } - if (!found) { - postPatternNotFound(keyword); - } - return { - type: actions.FIND_SET_KEYWORD, - keyword, - found, - }; + + return promise.then((keyword) => { + let found = find(keyword, backwards); + if (!found) { + window.getSelection().removeAllRanges(); + found = find(keyword, backwards); + } + if (found) { + postPatternFound(keyword); + } else { + postPatternNotFound(keyword); + } + + return { + type: actions.FIND_SET_KEYWORD, + keyword, + found, + }; + }); }; -const next = (keyword, reset) => { - return findNext(keyword, reset, false); +const next = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, false); }; -const prev = (keyword, reset) => { - return findNext(keyword, reset, true); +const prev = (currentKeyword, reset) => { + return findNext(currentKeyword, reset, true); }; export { next, prev }; diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.js index 3fd4dce..006b248 100644 --- a/src/content/actions/follow-controller.js +++ b/src/content/actions/follow-controller.js @@ -1,9 +1,10 @@ import actions from 'content/actions'; -const enable = (newTab) => { +const enable = (newTab, background) => { return { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab, + background, }; }; diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 5fd0f48..9171766 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -44,7 +44,8 @@ const exec = (operation, repeat, settings) => { case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, - newTab: operation.newTab + newTab: operation.newTab, + background: operation.background, }), '*'); case operations.NAVIGATE_HISTORY_PREV: return navigates.historyPrev(window); @@ -62,10 +63,7 @@ const exec = (operation, repeat, settings) => { return focuses.focusInput(); case operations.URLS_YANK: urls.yank(window); - return consoleFrames.postMessage(window.document, { - type: messages.CONSOLE_SHOW_INFO, - text: 'Current url yanked', - }); + return consoleFrames.postInfo(window.document, 'Current url yanked'); case operations.URLS_PASTE: return urls.paste(window, operation.newTab ? operation.newTab : false); default: diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js index 0238c71..4c1e385 100644 --- a/src/content/actions/setting.js +++ b/src/content/actions/setting.js @@ -1,10 +1,17 @@ import actions from 'content/actions'; import * as keyUtils from 'shared/utils/keys'; +import operations from 'shared/operations'; + +const reservedKeymaps = { + '<Esc>': { type: operations.CANCEL }, + '<C-[>': { type: operations.CANCEL }, +}; const set = (value) => { let entries = []; if (value.keymaps) { - entries = Object.entries(value.keymaps).map((entry) => { + let keymaps = Object.assign({}, value.keymaps, reservedKeymaps); + entries = Object.entries(keymaps).map((entry) => { return [ keyUtils.fromMapKeys(entry[0]), entry[1], |