A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
7 years ago
|
//
|
||
|
// window.find(aString, aCaseSensitive, aBackwards, aWrapAround,
|
||
7 years ago
|
// aWholeWord, aSearchInFrames);
|
||
7 years ago
|
//
|
||
|
// NOTE: window.find is not standard API
|
||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
|
||
|
|
||
7 years ago
|
import messages from 'shared/messages';
|
||
7 years ago
|
import actions from 'content/actions';
|
||
7 years ago
|
import * as consoleFrames from '../console-frames';
|
||
|
|
||
|
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
|
||
6 years ago
|
let found = window.find(string, caseSensitive, backwards, wrapScan);
|
||
|
if (found) {
|
||
|
return found;
|
||
|
}
|
||
|
window.getSelection().removeAllRanges();
|
||
7 years ago
|
return window.find(string, caseSensitive, backwards, wrapScan);
|
||
7 years ago
|
};
|
||
|
|
||
6 years ago
|
const findNext = async(currentKeyword, reset, backwards) => {
|
||
7 years ago
|
if (reset) {
|
||
|
window.getSelection().removeAllRanges();
|
||
|
}
|
||
|
|
||
6 years ago
|
let keyword = currentKeyword;
|
||
7 years ago
|
if (currentKeyword) {
|
||
|
browser.runtime.sendMessage({
|
||
|
type: messages.FIND_SET_KEYWORD,
|
||
|
keyword: currentKeyword,
|
||
|
});
|
||
7 years ago
|
} else {
|
||
6 years ago
|
keyword = await browser.runtime.sendMessage({
|
||
7 years ago
|
type: messages.FIND_GET_KEYWORD,
|
||
|
});
|
||
7 years ago
|
}
|
||
6 years ago
|
if (!keyword) {
|
||
6 years ago
|
return consoleFrames.postError('No previous search keywords');
|
||
6 years ago
|
}
|
||
|
let found = find(keyword, backwards);
|
||
|
if (found) {
|
||
6 years ago
|
consoleFrames.postInfo('Pattern found: ' + keyword);
|
||
6 years ago
|
} else {
|
||
6 years ago
|
consoleFrames.postError('Pattern not found: ' + keyword);
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
6 years ago
|
return {
|
||
|
type: actions.FIND_SET_KEYWORD,
|
||
|
keyword,
|
||
|
found,
|
||
|
};
|
||
7 years ago
|
};
|
||
|
|
||
7 years ago
|
const next = (currentKeyword, reset) => {
|
||
|
return findNext(currentKeyword, reset, false);
|
||
7 years ago
|
};
|
||
|
|
||
7 years ago
|
const prev = (currentKeyword, reset) => {
|
||
|
return findNext(currentKeyword, reset, true);
|
||
7 years ago
|
};
|
||
|
|
||
7 years ago
|
export { next, prev };
|