aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions/find.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-11 11:18:01 +0000
committerGitHub <noreply@github.com>2017-11-11 11:18:01 +0000
commit0630c8f56664ac48f4cf8799dc1d88a6388957a6 (patch)
treed9160c76f4c3435b0859669f1254b12eb92d183f /src/content/actions/find.js
parent86b534b1e1de03d51efb9f28cd32296d037f07fc (diff)
parentfe8a9283172e43e29480c4293c34565859c04c32 (diff)
Merge pull request #142 from ueokande/find-mode
[WIP] Find mode
Diffstat (limited to 'src/content/actions/find.js')
-rw-r--r--src/content/actions/find.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/content/actions/find.js b/src/content/actions/find.js
new file mode 100644
index 0000000..80d6210
--- /dev/null
+++ b/src/content/actions/find.js
@@ -0,0 +1,55 @@
+//
+// window.find(aString, aCaseSensitive, aBackwards, aWrapAround,
+// aWholeWord, aSearchInFrames);
+//
+// NOTE: window.find is not standard API
+// 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 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 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 { next, prev };