aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-03-07 21:34:37 +0900
committerGitHub <noreply@github.com>2018-03-07 21:34:37 +0900
commitd2a3c6cdd4d6ca564d9a80d281ba14648ffcc6eb (patch)
tree0de3603c8cffef056584413ef8a5a0dc051b8d8f /src/content/actions
parent72bf3cc2bdcc63864e064a64f7459aba004f4538 (diff)
parent92f8365be7127c3fa0276b1a6e890571f634622e (diff)
Merge pull request #355 from ueokande/search-across-pages
Search across pages
Diffstat (limited to 'src/content/actions')
-rw-r--r--src/content/actions/find.js59
-rw-r--r--src/content/actions/operation.js5
2 files changed, 43 insertions, 21 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/operation.js b/src/content/actions/operation.js
index 5fd0f48..71b2470 100644
--- a/src/content/actions/operation.js
+++ b/src/content/actions/operation.js
@@ -62,10 +62,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: