aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-11 15:53:46 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-11-11 16:16:10 +0900
commit12db4943ee54e1b0b48c806cde589254cb6fef51 (patch)
tree0b74672285e014c7c2850f2fb6d27f205240facd /src/content/actions
parent6db245892944b9e0a6a4f82b6e63453c880e3686 (diff)
show error on find and wrap search
Diffstat (limited to 'src/content/actions')
-rw-r--r--src/content/actions/find.js47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/content/actions/find.js b/src/content/actions/find.js
index 2d301fb..ac1b842 100644
--- a/src/content/actions/find.js
+++ b/src/content/actions/find.js
@@ -6,6 +6,13 @@
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
import actions from 'content/actions';
+import * as consoleFrames from '../console-frames';
+
+const postPatternNotFound = (pattern) => {
+ return consoleFrames.postError(
+ window.document,
+ 'Pattern not found: ' + pattern);
+};
const show = () => {
return { type: actions.FIND_SHOW };
@@ -15,22 +22,42 @@ const hide = () => {
return { type: actions.FIND_HIDE };
};
-const next = (keyword) => {
- // TODO Error on no matched
- window.find(keyword, false, false, true, false, true);
- return {
- type: actions.FIND_SET_KEYWORD,
- keyword,
- };
+const find = (string, backwards) => {
+ let caseSensitive = false;
+ let wrapScan = true;
+
+
+ // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work
+ // because of same origin policy
+ return window.find(string, caseSensitive, backwards, wrapScan);
};
-const prev = (keyword) => {
- // TODO Error on no matched
- window.find(keyword, false, true, true, false, true);
+const findNext = (keyword, reset, backwards) => {
+ if (reset) {
+ window.getSelection().removeAllRanges();
+ }
+
+ let found = find(keyword, backwards);
+ if (!found) {
+ window.getSelection().removeAllRanges();
+ found = find(keyword, backwards);
+ }
+ if (!found) {
+ postPatternNotFound(keyword);
+ }
return {
type: actions.FIND_SET_KEYWORD,
keyword,
+ found,
};
};
+const next = (keyword, reset) => {
+ return findNext(keyword, reset, false);
+};
+
+const prev = (keyword, reset) => {
+ return findNext(keyword, reset, true);
+};
+
export { show, hide, next, prev };