|
|
@ -6,6 +6,13 @@ |
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
|
|
|
|
|
|
|
|
|
|
|
|
import actions from 'content/actions'; |
|
|
|
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 = () => { |
|
|
|
const show = () => { |
|
|
|
return { type: actions.FIND_SHOW }; |
|
|
|
return { type: actions.FIND_SHOW }; |
|
|
@ -15,22 +22,42 @@ const hide = () => { |
|
|
|
return { type: actions.FIND_HIDE }; |
|
|
|
return { type: actions.FIND_HIDE }; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const next = (keyword) => { |
|
|
|
const find = (string, backwards) => { |
|
|
|
// TODO Error on no matched
|
|
|
|
let caseSensitive = false; |
|
|
|
window.find(keyword, false, false, true, false, true); |
|
|
|
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 { |
|
|
|
return { |
|
|
|
type: actions.FIND_SET_KEYWORD, |
|
|
|
type: actions.FIND_SET_KEYWORD, |
|
|
|
keyword, |
|
|
|
keyword, |
|
|
|
|
|
|
|
found, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const prev = (keyword) => { |
|
|
|
const next = (keyword, reset) => { |
|
|
|
// TODO Error on no matched
|
|
|
|
return findNext(keyword, reset, false); |
|
|
|
window.find(keyword, false, true, true, false, true); |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
type: actions.FIND_SET_KEYWORD, |
|
|
|
|
|
|
|
keyword, |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const prev = (keyword, reset) => { |
|
|
|
|
|
|
|
return findNext(keyword, reset, true); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export { show, hide, next, prev }; |
|
|
|
export { show, hide, next, prev }; |
|
|
|