aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/actions/find.js59
-rw-r--r--src/content/actions/operation.js5
-rw-r--r--src/content/components/top-content/find.js13
-rw-r--r--src/content/console-frames.js9
-rw-r--r--src/content/reducers/find.js2
5 files changed, 52 insertions, 36 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:
diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js
index bccf040..4d46d79 100644
--- a/src/content/components/top-content/find.js
+++ b/src/content/components/top-content/find.js
@@ -1,6 +1,5 @@
import * as findActions from 'content/actions/find';
import messages from 'shared/messages';
-import * as consoleFrames from '../../console-frames';
export default class FindComponent {
constructor(win, store) {
@@ -32,23 +31,11 @@ export default class FindComponent {
next() {
let state = this.store.getState().find;
-
- if (!state.found) {
- return consoleFrames.postError(
- window.document,
- 'Pattern not found: ' + state.keyword);
- }
return this.store.dispatch(findActions.next(state.keyword, false));
}
prev() {
let state = this.store.getState().find;
-
- if (!state.found) {
- return consoleFrames.postError(
- window.document,
- 'Pattern not found: ' + state.keyword);
- }
return this.store.dispatch(findActions.prev(state.keyword, false));
}
}
diff --git a/src/content/console-frames.js b/src/content/console-frames.js
index 515ae09..0c0ec02 100644
--- a/src/content/console-frames.js
+++ b/src/content/console-frames.js
@@ -28,4 +28,11 @@ const postError = (doc, message) => {
});
};
-export { initialize, blur, postMessage, postError };
+const postInfo = (doc, message) => {
+ return postMessage(doc, {
+ type: messages.CONSOLE_SHOW_INFO,
+ text: message,
+ });
+};
+
+export { initialize, blur, postError, postInfo };
diff --git a/src/content/reducers/find.js b/src/content/reducers/find.js
index eb43c37..8d63ee5 100644
--- a/src/content/reducers/find.js
+++ b/src/content/reducers/find.js
@@ -1,7 +1,7 @@
import actions from 'content/actions';
const defaultState = {
- keyword: '',
+ keyword: null,
found: false,
};